This program is by Wouter Peters and is used here by permission.

This program is supplied without representation or warranty of any kind. Wouter Peters and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Mastermind is originally a kind of board game for two. The board of the game consist of a series of four-holed rows. One is covered to hide it from one player. The other rows have four small 'marker' holes at one side.

The first player puts together a row of four coloured pegs. There are usually six colours available. Two or more pegs of the same colour are allowed. This array is hidden from the other player.

The other player has to discover the colours and positions of the pegs by putting together reasoned guesses of usually four coloured pegs (less than four pegs in one guess is allowed though, only the placed pegs will be evaluated). A guess is evaluated by the first player and is rewarded a white marker for every peg of the right colour that is placed in a wrong position and a black marker for every peg of the right colour that’s in the right place. These marker pegs are plugged into the marker-holes. The aim is to find the right configuration in as few as possible guesses.

The HP can only show one row of pegs with markers so either we must use the printer or use pen and paper to represent the board to keep track of the earlier guesses. This program can be run on a HP 41 C with or without a printer connected.

The calculator will generate a hidden array of four figures randomly chosen within the range of possible 'colours' and then prompt the player for his or her first guess. A guess is entered as a four-digit number. It is then parsed and processed. The program will return the appropriate white (0) or black (*) markers or will beep and return 'RIGHT' on a right guess.

- I haven't found a suitable character on my PC for the 'lazy T' associated with APPEND. The few times it occurs in the listing below (in lines 101, 111, 119 and 132) I’ve typed it as ‘lt’. So these are APPEND <space>, APPEND '*', APPEND '0' and APPEND 'RIGHT'
- A few Extended Functions are used: RCLFLAG, STOFLAG and REGMOVE. The first two are not really necessary. They have only a cosmetic function: to restore the numerical display format back to the state from before Mastermind was run (Mastermind needs a FIX 0 display). REGMOVE offers an easy way to copy registers 1-4 into 11-14 (Line 044, 045), but it can easily be rewritten to a series of RCL and STO statements to get the same result: a copy of Reg 1-4 into Reg 11-14.

Size= 21 Use of registers: R00= Random seed R01= code A R02= code B R03= code C R04= code D R05= guess A R06= guess B R07= guess C R08= guess D R09= # of right guessed places R10= loop counter #1 R11= scratch A R12= scratch B R13= scratch C R14= scratch D R15= address pointer #1 R16= address pointer #2 R17= # of right guessed figures R18= loop counter #2 R19= # of possible figures R20= num.display format flags

- Decide on the number of different figures you want to use and store this into register 19. To play in the classic setup: 6 STO 19
- XEQ "MM" will generate an hidden array and prompts you for the first guess ("?" in the display)
- enter for instance 1234 and press R/S . After your guess is parsed you'll see "1,2,3,4," scrolling through the display instead of the flying goose (a trick using a bug, the ignore error flag (25) and a flag operation on a nonexisting flag (any > 55), after evaluation of your guess it's marked, your marked guess displayed (for instance "1,2,3,4, *OO" one in a right place, two right figures in wrong places), a TONE is executed (no printer) or the output printed and the program STOPs. Now you can study your guess(es) deduct a new one enter it and press R/S again.
- Repeat 3 until you've got it right. The calculator will BEEP and you get a display saying that you had it right (for instance: '6,4,3,2 RIGHT'). The program winds up (restores the original numerical display format) and halts at the END, so you can simply start another play by pressing R/S.

001 LBL "MM" 002 RCLFLAG 003 STO 20 004 FIX 0 005 4 006 STO 10 007 LBL 01 008 XEQ 11 009 RCL 19 010 * 011 INT 012 1 013 + 014 STO IND 10 015 DSE 10 016 GTO 01 017 CF 22 018 LBL A 019 FC? 22 020 ? 021 FC? 22 022 PROMPT 023 1 E4 024 / 025 STO L 026 XEQ 12 027 STO 05 028 XEQ 12 029 STO 06 030 XEQ 12 031 STO 07 032 XEQ 12 033 STO 08 034 CLA 035 ARCL 05 036 ARCL 06 037 ARCL 07 038 ARCL 08 039 FS? 55 040 CF 21 041 SF 25 042 AVIEW 043 SF 99 044 1,011004 045 REGMOVE 046 5 047 STO 15 048 11 049 STO 16 050 4 051 STO 10 052 STO 18 053 STO 17 054 STO -17 055 LBL 02 056 RCL IND 15 057 RCL IND 16 058 X=Y? 059 GTO 03 060 1 061 ST+ 16 062 DSE 10 063 GTO 02 064 GTO 04 065 LBL 03 066 ISG 17 067 STO X 068 PI 069 STO IND 16 070 LBL 04 071 1 072 ST+15 073 11 074 ST 16 075 4 076 STO 10 077 DSE 18 078 GTO 02 079 STO 09 080 ST- 09 081 RCL 01 082 RCL 05 083 X=Y? 084 ISG 09 085 STO X 086 RCL 02 087 RCL 06 088 X=Y? 089 ISG 09 090 STO X 091 RCL 03 092 RCL 07 093 X=Y? 094 ISG 09 095 STO X 096 RCL 04 097 RCL 08 098 X=Y? 100 STO X 101 "lt " 102 RCL 09 103 ST- 17 104 STO 10 105 X=0? 106 GTO 06 107 4 108 X=Y? 109 GTO 09 110 LBL 05 111 "lt*" 112 DSE 10 113 GTO 05 114 LBL 06 115 RCL 17 116 X=0? 117 GTO 08 118 LBL 07 119 "ltO" 120 DSE 17 121 GTO 07 122 LBL 08 123 FS? 55 124 SF 21 125 AVIEW 126 FC? 55 127 TONE 7 128 CF 22 129 STOP 130 GTO A 131 LBL 09 132 "ltRIGHT" 133 FS? 55 134 SF 21 135 AVIEW 136 BEEP 137 ADV 138 GTO 10 139 LBL 11 140 RCL 00 141 9821 142 * 143 .211327 144 + 145 FRC 146 STO 00 147 RTN 148 LBL 12 149 LASTX 150 FRC 151 10 152 * 153 INT 154 RTN 155 LBL 10 156 RCL 20 157 36,41 158 STOFLAG 159 END

Go back to the HP-41 software library

Go back to the general software library

Go
back to the main exhibit hall