# Mastermind

Yay!

Mastermind is a short type-in from Your Computer magazine (December 1986, pp. 80/81).

Gameplay is the same as the well-known Mastermind board game—a black peg signifies that a digit is correct and in the correct position, while a white peg shows that a digit is part of the solution but in the wrong position.

## Source code

```10 '**** MASTER-MIND ****
11 ' from Your Computer, December 1986, Vol 6, n° 12.
12 ' scans: ftp://ftp.worldofspectrum.org/pub/sinclair/magazines/YourComputer/Issue8612/Pages/YourComputer861200080.jpg
20 mode 1
30 ink 0,15:ink 1,1
40 dim g(4),ans(4)
50 cls
60 for i=1 to 4
70 ans(i)=int(rnd*6)
80 next i
90 locate 14,2:print" MASTER-MIND"
100 print:print"     You have to guess a four digit"
110 print" number. Each digit must be between"
120 print" 0 and 5 e.g. 2501 or 4431."
130 print"     You will be allowed a maximum "
140 print"  of 12 guesses!"
150 print
160 for g=1 to 12
170 bl=0:wh=0
180 locate 2,g+8
190 print " Enter guess ";g;" ";:locate 20,g+8:input "- ", guess\$
200 if len(guess\$)<> 4 then print" Invalid entry - try again ":goto 180
210 for j=1 to 4:g(j)=asc(mid\$(guess\$,j,1))-48
220 if g(j)<0 or g(j)>5 then print " Invalid - try again ":goto 180
230 next j
240 locate 26,g+8:print using "&"; space\$(200)
250 for k=1 to 4:if g(k)=ans(k) then bl=bl+1
260 if bl=4 then locate 2,22:print" Well done - you guessed correctly. ":goto 440
270 next k
280 for w=1 to 4
290 for x=1 to 4
300 if ans(w)=g(x) then wh=wh+1:g(x)=6:goto 320
310 next x
320 next w
330 wh=wh-bl
340 locate 27,g+8
350 pen 2:ink 2,0
360 if bl<1 then 380
370 for c=1 to bl:print using "&"; chr\$(143);" ";:next c
380 if wh<1 then 400
390 pen 3:ink 3,26:for c2=1 to wh:print chr\$(143);" ";:next c2
400 pen 1
410 next g