TITLE : Super Master Mind AUTHOR: Roy F A Maclean, r.f.a.maclean@hw.ac.uk DATE: 12th February 1996 MAKE: CASIO MODEL: any SIZE: 341 NOTES: This file may be freely distributed as long as it remains unaltered. The Notation file can be read at: http://www.cee.hw.ac.uk/~mthrfam/calc/casio/not.html <> not equals => implication (or 'then do') (or 'double arrow', if you want!) -> assignment # display (except after 'Ran') {pi} pi t means a small '10' above the log button The variable O is NEVER used. If you see something in the program listing which looks like an O then it will be the number zero ('0') In the board game 'Super Master Mind' one player chooses 5 coloured pegs from a large supply. There are 8 different colours to choose from. The second player has to guess which colours he chose and what order they are in. After each guess the first player says how many pegs are the right colour and place, and how many are right colour but wrong place. This program emulates super master mind by using a 5 digit number instead of 5 pegs and the numbers 0~7 instead of the eight colours. The calculator comes up with a random 5 digit number containing the figures 0~7 and you have to guess what it is. It will tell you how many exact matches there are and how many are the right figure but in the wrong place. e.g. if the program has chosen 77021 and you guessed 75573, ^ ^ in out then it would say you have one OUT of place and one IN place. If you guess correctly then the program ends and tells you how many guesses you had. If at any time you wish to give up then enter the {pi} symbol and it will tell you what the number was. If you take 15 guesses then it will say you've had too many guesses and the game ends You don't have to enter all five digits. If you enter 24 then it will take this as 00024. See if you can find a method which always reveals the answer in less than ten guesses. (apart from giving up!) Below is the program complete with comments. After the program is a list of what each variable is used for. __________________________________________ Lbl 0 "SUPER MASTERMIND" Mcl:5->N - sets variables up for loop1 Lbl 1 - Loop 1-generates 5 random digits 0~7 Int 8Ran#->A[N] - puts them in array A[1]~A[5] i.e. valuemem B~F A[N]t(5-N)+A->A - 't' means press to get small '10' Dsz N:Goto 1 - end of Loop 1 Lbl 2 - Loop 2 is main loop after each guess Isz G - increases the guess counter G=16=>Goto 7 - too many guesses implies end of game "GUESS"?->J J={pi}=>Goto 7 - if user enters pi then game over J<0=>Goto 2 }next three lines are error checkers to see if L>8ee4=>Goto 2 }guess is within range. Frac J<>0=>Goto 2 } 5->N:0->M - sets up variables for loop3 Lbl 3 - this loop compares guess for exact matches 6-N->K - saves memory by not using 6-N every time Int (10Frac (J/tN))->U[K] - extracts a digit from the guess A[K]-U[K]->P[K] P[K]=0=>Isz M Dsz N:Goto 3 - end of loop 3 M=5=>Goto 8 - if all 5 digits in correct place then end of game . . This next bit checks for in wrong place 5->N:0->L Lbl 4 - loop 4 compares each digit of guess with each of Ans P[N]=0=>Goto 6 5->P:Lbl 5 U[N]<>A[P]=>Goto 7 } don't increase 'L' if not same P[P]={pi}=>Goto 7 } or if position in guess already matched P[P]=0=>Goto 7 } or if exact match already matched Isz L:{pi}->P[P]:Goto 6 Lbl 7:Dsz P:Goto 5 Lbl 6 Dsz N:Goto 4 . . "OUT":L# "IN":M# Goto 2 - go back to new guess Lbl 8 "GAME OVER" "Ans":A# M=5=>"TURNS":M=5=>G# Goto 0 - go back for new game