Mastermind for HP-42s



#14

Created in fits of boredom in school ~25 years ago, printed on thermal paper, lost and forgotten. Now recreated from memory, probably only similar to the original in functionality. Since the display has limited colour capabilities, the integers 1-7 are used instead.

Issues:

1) Your first guess is always '1234'. It would be easy to change, but it is the way I play, so I don't bother

2) I am sure there are superfluous redundancies in there, feel free to suggest improvements.

Issues for users of the '42s' iOS emulator in particular:

1) Assumes 4-level stack. (Disable dynamic stack)

2) Uses flags 1-4, switch off flag indicators or have the game spoiled.


00 { 289-Byte Prgm }
01>LBL "MIND"
02 MVAR " "
03 MVAR "P1"
04 MVAR "P2"
05 MVAR "P3"
06 MVAR "P4"
07 7
08 STO "N"
09 4
10 STO "P4"
11 STO 00
12 3
13 STO "P3"
14 2
15 STO "P2"
16 1
17 STO "P1"
18>LBL 00
19 XEQ 42
20 DSE 00
21 GTO 00
22 0
23 STO 09
24>LBL 01
25 1
26 RCL+ 09
27 STO 09
28 "Guess #"
29 AIP
30 |-"("
31 XEQ 02
32 RCL 05
33 AIP
34 RCL 06
35 AIP
36 RCL 07
37 AIP
38 RCL 08
39 AIP
40 |-"): "
41 4
42 RCL 11
43 X=Y?
44 GTO 41
45 AIP
46 |-"B/"
47 RCL 12
48 AIP
49 |-"W"
50 VARMENU "MIND"
51 AVIEW
52 STOP
53 GTO 01
54>LBL 02
55 8
56>LBL 03
57 CF IND ST X
58 DSE ST X
59 GTO 03
60 0
61 STO 11
62 STO 12
63 RCL "P1"
64 STO 05
65 RCL "P2"
66 STO 06
67 RCL "P3"
68 STO 07
69 RCL "P4"
70 STO 08
71 4
72>LBL 04
73 XEQ 11
74 Rv
75 Rv
76 DSE ST X
77 GTO 04
78 8.004
79>LBL 05
80 4
81>LBL 06
82 XEQ 12
83 DSE ST X
84 GTO 06
85 Rv
86 DSE ST X
87 GTO 05
88 RTN
89>LBL 11
90 4
91 RCL+ ST Y
92 RCL IND ST Y
93 RCL- IND ST Y
94 X!=0?
95 RTN
96 SF IND ST Y
97 Rv
98 SF IND ST Y
99 1
100 STO+ 11
101 RTN
102>LBL 12
103 FS? IND ST X
104 RTN
105 FS? IND ST Y
106 RTN
107 RCL IND ST Y
108 RCL- IND ST Y
109 X!=0?
110 GTO 20
111 Rv
112 SF IND ST X
113 SF IND ST Y
114 1
115 STO+ 12
116>LBL 20
117 Rv
118 RTN
119>LBL 41
120 |-"Right!"
121 AVIEW
122 STOP
123 GTO "MIND"
124>LBL 42
125 RAN
126 RCL* "N"
127 IP
128 1
129 +
130 STO IND 00
131 .END.

Enjoy!


#15

I've no HP42s and can't test but the code seems fine and compact.

Here is an old version I wrote long time ago for CASIO FX-602P

http://www.ledudu.com/casio602p/mastermind.htm

By the way I'm curious if it exists for such calcultors a program to solve the game in a minimum of moves... I wrote this in the past for the 602P (probably not with the best strategy) but I don't remember at all how I did

Edited: 30 Aug 2013, 5:09 a.m.


#16

Quote:
I've no HP42s and can't test

The code runs under free42 and its derivatives...

#17

Quote:
By the way I'm curious if it exists for such calcultors a program to solve the game in a minimum of moves

Very good question. I found
this paper by Don Knuth which has a "guaranteed win in five" performance, but for 6 colors and repetitions allowed. I wonder if Knuth's recipe can be generalized?

--T

#18

Thanks! You should submit this to the Program Library here at MoHPC.


#19

I could do that. Would you need much more than the above?

--T

#20

I only had an HL33C and despite only having 49 programming steps I remember that I tried to implement a version of Mastermind.

When I found the hard copy I thought I'd post it here as a comparison:


001=0            0
002=23 5 STO 5
003=12 37 GSB 37
004=23 1 STO 1
005=12 37 GSB 37
006=23 2 STO 2
007=12 37 GSB 37
008=23 3 STO 3
009=12 37 GSB 37
010=23 4 STO 4
011=24 1 RCL 1
012=12 27 GSB 27
013=24 2 RCL 2
014=12 27 GSB 27
015=24 3 RCL 3
016=12 27 GSB 27
017=24 4 RCL 4
018=12 27 GSB 27
019=24 5 RCL 5
020=14 74 PSE
021=4 4
022=14 71 X=Y
023=13 00 GTO 00
024=0 0
025=23 5 STO 5
026=13 11 GTO 11
027=23 7 STO 7
028=14 34 CL STK
029=74 R/S
030=23 41 7 STO- 7
031=24 7 RCL 7
032=15 61 X!=0
033=15 12 RTN
034=1 1
035=23 51 5 STO+ 5
036=15 12 RTN
037=24 0 RCL 0
038=9 9
039=9 9
040=7 7
041=61 x
042=15 33 FRAC
043=23 0 STO 0
044=6 6
045=61 x
046=15 32 INT
047=14 11 1 FIX 1
048=15 12 RTN


To run the program

          .5284163  - Random number seed
STO 0 - Store random number seed


1. R/S - Start
2. 4 - First digit of guess
3. R/S
4. 3 - Second digit of guess
5. R/S
6. 0 - Third digit of guess
7. R/S
8. 0 - Fourth digit of guess
9. R/S
10. 3.0 - You have 3 digits in the correct position
11. - Go to step 1



Program halts when (if) you guess all 4 digits correctly!

Looking back at my original code I'd definatly do some things differently, but I don't think I could shorten things enough to allow me to check for both black and white pegs...


Mike T.

#21

Quote:
I only had an HL33C and despite only having 49 programming steps I remember that I tried to implement a version of Mastermind.

That's a great advantage! Having much more steps at my disposal only made me lazy and inefficient :-) (I had a TI-59 in 1982 and an HP-15C in 1983). 125 steps on the HP-15C:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv014.cgi?read=68346

This is slightly shorter (117 steps).

Here a nice wp34s implementation by Jeff O. Also, a Turbo Pascal version.

Regards,

Gerson.


#22

All of these variations stipulate no repeated digits, which certainly makes the scoring (and guessing) much simpler. Part of the reason I need eight flags in the 42s version is to deal with the complexity due to repeated digits -- I must keep track of every digit that has already been awarded a (black or white) pin, both in the guess and in the solution.


#23

Tom

I wrote an HP-25c version (~= 1975)of MM that closely conforms with the original board game using the following convention:

digits 1-9 as substitutes for the colors

TENS digit are the BLACK flags & the ONES digit are the WHITE flags

&

repeat digits allowed, code length variable from 3 to 6 digits.

This sounds close to your intent w the 42s version. It took me a while to respond because my 25c emulator seems to have a STACK disable anomaly.

[Machine]
Simulator=RPN Calc 25
[Registers]
R00=1.0 preLoaded CONSTANT
R01=0
R02=0
R03=0
R04=0
R05=2468 preLoaded, 3-6 digit CODE
R06=0
R07=0.1 preLoaded CONSTANT
[Program]
Precision=1
Display=0 FIX 0
Mode=1
001=23 1 STO 1
002=23 2 STO 2
003=24 5 RCL 5
004=23 4 STO 4
005=23 3 STO 3
006=24 7 RCL 7
007=23 61 3 STO x 3
008=23 61 2 STO x 2
009=24 3 RCL 3
010=15 71 X=0
011=13 36 GTO 36
012=15 1 FRAC
013=23 41 3 STO - 3
014=24 2 RCL 2
015=15 1 FRAC
016=23 41 2 STO - 2
017=15 61 X<>0
018=14 61 X<>Y
019=13 06 GTO 06
020=9 9
021=23 51 6 STO + 6
022=13 06 GTO 06
023=23 61 4 STO x 4
024=23 71 0 STO / 0
025=61 x
026=15 1 FRAC
027=15 61 X<>0
028=14 61 X<>Y
029=13 33 GTO 33
030=23 41 4 STO -4
031=1 1
032=13 21 GTO 21
033=22 RDN -- *see note
034=24 4 RCL 4
035=14 1 INT
036=24 7 RCL 7
037=14 41 X<Y
038=13 23 GTO 23
039=23 61 1 STO x 1
040=24 0 RCL 0
041=23 61 4 STO x 4
042=23 71 0 STO / 0
043=24 1 RCL 1
044=15 1 FRAC
045=23 41 1 STO - 1
046=15 61 X<>0
047=13 34 GTO 34
048=24 6 RCL 6
049=23 41 6 STO - 6
<EoP>
Registers initialization is important
R0 = 1.0
R7 = 0.1
R6 = 0.0
R5 = 3 to 6 digit code
Program STARTS @ Line 00 with R/S & loops with the SCORE displayed in the X stack register (FIX 0) as Nn where N = # of digits (colors) in correct position (black flags) & n = # of digits (colors) out of correct position (white flags).

My scoring algorithm is slightly unorthodox (unconventional) in that I score the BLACK-flags value twice, thus avoiding the usual complications asscociated with the WHITE-flags scoring algorithm {slightly convoluted, but VERY effective}.

*note = original listing used CLX to disable stack lift but the emulator seems to omit this behavior - took me a little while to run to ground this discrepancy.

I hope this helps you w your interpretation of a CLASSIC game.

BEST!

SlideRule
{spelling edits ONLY 20130909}


Edited: 9 Sept 2013, 7:34 p.m. after one or more responses were posted


#24

That looks amazingly compact, Kimberly. I'm impressed. I'll try to figure out how it works, to see if I can shorten my own offering with the same tricks.

What do you mean by "3-6 digit code"? Does the program work with variable-length codes? Unchanged?

Thank you,

--T


#25

Tom

YES, the length of the CODE is variable. I suggest a length of 3 as a minimum (ie 246) so as to avoid a 'trivial' session and a length of 6 as a maximum (ie 123456) to ameliorate complexity. The PRGM scoring routine accommodates a variable length CODE.

Also, the range of digits for the CODE varies from ONE thru NINE and accommodates repeat digits: 12241 is a VALID CODE for the program.

I no longer own a working HP-25 so I validated this archive routine using Mike T's simulators from

http://www.hpmuseum.org/guest/miket/rpn25exe.zip

and is the source of the submitted listing.

If you have any comments / alibis, please feel free. Thanks for the feedback, BEST!

SlideRule

#26

Mike

the HP-25 program above should work unaltered for a 33, ie runs on the RPN Calc 33 simulator OK.

Enjoy!

SlideRule

Edited: 2 Sept 2013, 3:46 p.m.


Possibly Related Threads...
Thread Author Replies Views Last Post
  MASTERMIND for the HP PRIME Tony Gallo 6 317 11-24-2013, 01:44 PM
Last Post: Tony Gallo
  42s questions and 42s vs 35s snaggs 13 680 09-19-2011, 02:44 AM
Last Post: snaggs

Forum Jump: