# TITLE : Super Master Mind, version 1.1 # AUTHOR: Roy F A Maclean, # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 12Feb1996 # MAKE: CASIO # MODEL: any # SIZE: 341 # NOTES: Please read the notation page at the above website. # # <> not equals # => implication # -> assignment # _ underscore means display # \10^ means a small '10' above the log button # \pi Pi symbol # # 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]\10^(5-N)+A->A ; \10^ 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 8 ; too many guesses implies end of game "GUESS"?->J J=\pi=>Goto 8 ; if user enters pi then game over J<0=>Goto 2 ; next three lines are error checkers to see if J>8 \10^ 4=>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/\10^N))->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 5->N:0->L ; This next bit checks for in wrong place 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 # __________________________________________ # # A Ans # B B~F (i.e. A[1]~A[5]) hold digits of Ans # C " # D " # E " # F " # G Guess Counter # H not used # I not used # J Guess # K Memory Saving Substitute for '6-N' # L Out of Place Counter # M In Place Counter # N Loop Counter # O not used # P 2nd Loop Counter # Q Q~T (i.e. P[1]~P[5]) hold difference between guess and answer digits # R " # S " # T " # U " # V V~Z (i.e. U[1]~U[5]) hold digits of guess # W " # X " # Y " # Z " @@ Program "SMM" Lbl 0 "SUPER MASTERMIND" Mcl:5->N Lbl 1 Int 8Ran#->A[N] A[N]\10^(5-N)+A->A Dsz N:Goto 1 Lbl 2 Isz G G=16=>Goto 8 "GUESS"?->J J=\pi=>Goto 8 J<0=>Goto 2 J>8 \10^ 4=>Goto 2 Frac J<>0=>Goto 2 5->N:0->M Lbl 3 6-N->K Int (10Frac (J/\10^N))->U[K] A[K]-U[K]->P[K] P[K]=0=>Isz M Dsz N:Goto 3 M=5=>Goto 8 5->N:0->L Lbl 4 P[N]=0=>Goto 6 5->P:Lbl 5 U[N]<>A[P]=>Goto 7 P[P]=\pi=>Goto 7 P[P]=0=>Goto 7 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 Lbl 8 "GAME OVER" "Ans":A_ M=5=>"TURNS":M=5=>G_ Goto 0