Mastermind (Syntax)

Developer(s): Walter Bacon
Date: 1981
Type: Program
Platform(s): ZX80
Tags: Game

The number-guessing game for the ZX80 (4K ROM). The computer picks a secret five-digit number and you enter a guess one digit at a time, pressing NEWLINE after each. You score 10 points for each right digit in the right place and 1 for a right digit in the wrong place; 50 means you have it.

After each score, press NEWLINE to guess again or enter Y to give up and see the number; after a win, M starts a new game.

Published in Syntax February 1981 (Mastermind).

Related Articles

Number guessing game.

Image Gallery

Source Code

 10 DIM A(5)
 15 DIM B(5)
 20 DIM C(5)
 25 LET T=0
 30 RANDOMISE
 35 FOR J=1 TO 5
 40 LET A(J)=(RND(10)-1)
 45 NEXT J
 50 CLS
 55 FOR J=1 TO 5
 60 LET C(J)=0
 65 NEXT J
 70 PRINT "ENTER 1ST DIGIT OF GUESS"
 75 INPUT B(1)
 80 PRINT "2ND DIGIT?"
 85 INPUT B(2)
 90 PRINT "3RD?"
 95 INPUT B(3)
100 PRINT "4TH?"
105 INPUT B(4)
110 PRINT "5TH?"
115 INPUT B(5)
120 PRINT B(1);B(2);B(3);B(4);B(5)
125 LET S=0
130 FOR J=1 TO 5
135 IF NOT A(J)=B(J) THEN GO TO 150
140 LET S=S+10
145 LET C(J)=1
150 NEXT J
155 FOR J=1 TO 5
160 FOR K=1 TO 5
165 IF NOT A(J)=B(J) AND C(K)=0 AND B(J)=A(K) THEN GO TO 175
170 GO TO 190
175 LET S=S+1
180 LET C(K)=1
185 GO TO 195
190 NEXT K
195 NEXT J
200 LET T=T+1
205 PRINT "SCORE IS ";S;" TRIES =";T
210 IF S=50 THEN PRINT "CONGRATULATIONS. MORE? ENTER M"
215 IF NOT S=50 THEN PRINT "GIVE UP? ENTER Y OR HIT NEWLINE"
220 INPUT D$
225 IF D$="" THEN GO TO 50
230 IF D$="M" THEN GO TO 10
235 PRINT A(1);A(2);A(3);A(4);A(5)

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.