Mastermind

Date: 1984
Type: Diskette
Platform(s): QL
Tags: Game

Mastermind asks you to guess three numbers in the correct order in eight tries. After each guess it shows how many numbers are correct and how many wrong, without saying which. Two people can play, or one player can take on the computer on an easy setting (numbers 1 to 7) or a hard one (1 to 9).

The REMs credit J.W. Robinson and S. Brailsford, call it version 1.1, and date it September 1984. J.W. Robinson’s Catalog utility is in the QUANTA and IQLUG SuperBASIC Utilities download.

Program Analysis

INIT prints the instructions and the F1 to F3 menu, SCREEN draws the guess table, and ENTER, TEST and WIN take a guess, score it and report a win.

It came from a QL owner’s floppy copies of QUANTA and IQLUG library material, imaged double-stepped so that only half of each disk survived; this file read back complete. The download holds the files exactly as recovered and a QL5A floppy image, Mastermind.img, with the same files and their QDOS headers. Mount the image as FLP1_ (drop it on the QLRun page, or use it as a floppy image in sQLux, QPC2 or Q-emuLator) and type lrun flp1_master_bas.

Tested in QLRun with the JS ROM: the instruction screen.

Image Gallery

Source Code

100 REMark MASTERMIND PROGRAM
110 REMark FOR SINCLAIR QL COMPUTER
120 REMark BY J.W.ROBINSON
130 REMark AND S.BRAILSFORD
135 REMark VERSION 1.1
140 REMark  SEPTEMBER 1984
150 INIT
160 QUEST
170 GAME
180 DEFine PROCedure GAME
190 count%=0
200 WRONG%=3
210 SCREEN
220 GUESS
230 ENTER
240 QUEST
250 END DEFine 
260 DEFine PROCedure SCREEN
270 CLS#2:CLS#0:CLS
280 BORDER#1,10,5
290 PAPER 1:INK 6:CLS
300 CSIZE 0,0
310 UNDER 1
320 PRINT ' GUESS NO  1  2  3  CORRECT WRONG '
330 UNDER 0
340 LINE 0,89 TO 255,89
350 LINE 49,0 TO 49,100
360 LINE 63,0 TO 63,100
370 LINE 78,0 TO 78,100
380 LINE 93,0 TO 93,100
390 LINE 136,0 TO 136,100
400 AT 1,23:PRINT '        ':AT 1,23:PRINT'POSITION'
410 OVER 1
420 CSIZE 0,1
430 FOR LOOP= 1 TO 8
440 AT LOOP,2:PRINT CHR$(48+LOOP)
450 NEXT LOOP
460 FOR LOOP= 12,23,34,45,57,67,78
470 LINE 0,LOOP TO 255,LOOP
480 NEXT LOOP
490 END DEFine 
500 DEFine PROCedure GUESS
510 CSIZE#0;1,0
520 FOR LOOP= 1 TO 3
530 CLS#0
540 INPUT#0;"ENTER NUMBER : "&LOOP&' ';NUMBER$(LOOP)
550 KEY NUMBER$(LOOP),540
560 NEXT LOOP
570 CLS#0
580 END DEFine 
590 DEFine PROCedure ENTER
600 GOES%=0
610 CSIZE#0,1,0
620 DIM num$(3)
630 AT 1,0
640 FOR LOOP = 1 TO 8
650 GOES%=GOES%+1
660 OVER 1
670 CLS#0:INPUT#0;'ENTER GUESS NUMBER : 1 ';num$(1)
680 KEY num$(1),670
690 AT LOOP,10:PRINT;num$(1)
700 CLS#0:INPUT#0;'ENTER GUESS NUMBER : 2 ';num$(2)
710 KEY num$(2),700
720 CLS#0:AT LOOP,13:PRINT num$(2)
730 CLS#0:INPUT#0;'ENTER GUESS NUMBER : 3 ';num$(3)
740 KEY num$(3),730
750 AT LOOP,16:PRINT num$(3)
760 TEST
770 NEXT LOOP
780 CSIZE#0,1,0
790 PRINT #0;'NUMBERS WERE:-'
800 PRINT #0; NUMBER$(1);' ';NUMBER$(2);' ';NUMBER$(3)
810 PAUSE 200
820 BORDER 3,6
830 CLS
840 QUEST
850 END DEFine 
860 DEFine PROCedure TEST
870 WRONG%=3
880 IF num$(1)=NUMBER$(1) THEN count%=count%+1
890 IF num$(2)=NUMBER$(2) THEN count%=count%+1
900 IF num$(3)=NUMBER$(3) THEN count%=count%+1
910 AT LOOP,21:PRINT count%
920 AT LOOP,29:PRINT WRONG%-count%
930 IF count%=3 THEN PAUSE 50
940 IF count%=3 THEN WIN
950 count%=0
960 END DEFine 
970 DEFine PROCedure WIN
980 CLS#1
990 FOR LOOP= 60 TO 0 STEP -2
1000 BORDER LOOP,(RND*8)
1010 NEXT LOOP
1020 AT 4,13:FLASH 1:PRINT 'WELL DONE !'
1030 AT 5,14:PRINT 'YOU WIN'
1040 FLASH 0
1050 FOR Z = 1 TO 3
1060 FOR LOOP= 0 TO 100
1070 BEEP 100,LOOP,(LOOP+100),-100,7,15
1080 NEXT LOOP
1090 NEXT Z
1100 count%=0
1110 CLS
1120 QUEST
1130 END DEFine 
1140 DEFine PROCedure INIT
1150 PAPER 1
1160 CLS#0:CLS:CLS#2
1170 BORDER 3,6
1180 count%=0
1190 DIM NUMBER$(3)
1200 CSIZE 0,0
1210 PRINT
1220 PRINT TO 12;'Mastermind'
1230 PRINT '  This is a game for Two players,'
1240 PRINT '  or One player against the''  Computer.'
1250 PRINT '  The aim of the game is to guess'
1260 PRINT ' Three numbers in the correct''  Order.'
1270 PRINT '  If two people are playing, I would'
1280 PRINT '  Recomend that you only use numbers'
1290 PRINT '  between 1 and 7'
1300 PRINT '  If you are playing the computer'
1310 PRINT '  It will choose numbers between'
1320 PRINT '  1 and 7 in easy mode or numbers'
1330 PRINT '  1 and 9 in hard mode.'
1340 PRINT#0;'Press any key to continue'
1350 PAUSE 1000
1360 CLS:PRINT
1370 PRINT TO 12;'Mastermind'
1380 PRINT '  You will get 8 chances to guess'
1390 PRINT '  the numbers.  If you do not get'
1400 PRINT '  the numbers you will be shown'
1410 PRINT '  what the numbers were.'
1420 PRINT '  When you have entered your guess'
1430 PRINT '  the computer will tell you if you'
1440 PRINT '  have got any correct, but it'
1450 PRINT '  will not tell you which ones.'
1460 CSIZE 3,0
1470 PRINT'       GOOD LUCK !!!'
1480 END DEFine 
1490 DEFine PROCedure QUEST
1500 CSIZE 1,0
1510 PRINT '  F1 = TWO PLAYERS'
1520 PRINT '  F2 = PLAY COMPUTER (EASY)'
1530 PRINT '  F3 = PLAY COMPUTER (HARD)'
1540 REPeat LOOP
1550 KEY1=KEYROW(0)
1560 IF KEY1=2 THEN SCREEN:GUESS:ENTER:GAME
1570 IF KEY1=8 THEN SCREEN:COMP(0):ENTER:TEST
1580 IF KEY1=16 THEN SCREEN:COMP(1):ENTER:TEST
1590 END REPeat LOOP
1600 END DEFine 
1610 DEFine PROCedure COMP (DIF)
1620 SELect ON DIF
1630 =0
1640 NUMBER$(1)=RND(6)+1
1650 NUMBER$(2)=RND(6)+1
1660 NUMBER$(3)=RND(6)+1
1670 =1
1680 NUMBER$(1)=RND(8)+1
1690 NUMBER$(2)=RND(8)+1
1700 NUMBER$(3)=RND(8)+1
1710 END SELect 
1720 END DEFine 
1730 DEFine PROCedure KEY (key$,ba)
1740 check$=key$
1750 back=ba
1760 IF check$=" " THEN errors:GO TO back
1770 IF CODE(check$)<49 OR CODE(check$)>57 THEN errors:GO TO back
1780 END DEFine 
1790 DEFine PROCedure errors
1800 PAPER#0;6:INK#0;0:CLS#0
1810 PRINT#0;'Please enter Numbers between'
1820 PRINT#0;TO 6;'1 and 9 only.'
1830 FOR Z=1 TO 3
1840 BEEP 500,10:BEEP 500,20:BEEP 500,5
1850 NEXT Z
1860 PAUSE 10
1870 PAPER#0;0:INK#0;7
1880 FOR Z=1 TO 50
1890 SCROLL#0,1
1900 NEXT Z
1910 END DEFine

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