The Museum of HP Calculators


Hexapawn for the HP-41C

This program was first published in the HP-41C Users' Library Solutions: Games by Hewlett-Packard and is used here by permission.

This program is supplied without representation or warranty of any kind. Hewlett-Packard Company 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.

Overview

Hexapawn is a game which is programmed to learn from its mistakes. The game is played with chess pawns on a 3x3 board. Pawns may advance one square at a time or capture the opponent's pawns by moving diagonally one square. The game starts with the pawns positioned as follows:

Note the resemblance between the 41C digit keys and the board numbering. The three allowed opening moves for the first player (in this example, white) are 1 to 4 (keyed as 1.4), 2 to 5 (2.5), and 3 to 6 (3.6).

Black's three possible responses to white's 1.4 move are 8 to 4, 8 to 5, and 9 to 6.

Black can move diagonally and capture white (8 to 4), or he can move either pawns 8 or 9 straight ahead one square. The black pawn at 7 is blocked. Note that the only way a pawn can move to an open square is straight ahead. Also the only way a pawn can capture is by moving diagonally.

The game is won by advancing a pawn to the third row, capturing all of the opponent's pawns, or creating a position in which the opponent cannot move.

Moves are made by keying in the board position of the pawn to be moved, a decimal point, then the board position the pawn is to be moved to. The 41C does not check for illegal moves; therefore, you are on your honor not to cheat. The 41C selects its move at random, but if it is then punished, it remembers not to make that move in that situation. Thus, if the machine makes a poor move and is punished, it will not repeat the mistake.* Also, if the mirror image game is played, it will not make the mirror image of the poor move. If a point is reached in a game where all possible moves for a certain board configuration have received previous punishment, "NO MOVE" and "YOU WIN" is displayed, just as if there really were no move. If you cannot move, you can if you wish be a good sport and tell the 41C by keying 0 for your move. It will respond with "I WIN". If chess pawns are not available for visualization, different colored coins work well.

*Similarly, you can punish good moves to make it play a losing game.

Note: Requires 2 Memory Modules on HP-41C

Instructions

Step

Instructions

Input Data/Units

Keys

Output Data/Units

1

Enter program

     

2

Initialize type of game:  human first,

 

[XEQ] HUMAN 

SEED? 

                           or machine first.  

[XEQ] MACHINE 

SEED? 

3

Key in a seed for the random number generator between 0 and 1. (Just hit [R/S] if a seed has been previously entered.)

seed 

[R/S]

READY (or)

 

 

 

 

( ) to ( )

 4

Key in your move FROM.TO

F.T

[R/S]

( ) to ( )

  Repeat step 4 until game is over    

 

OPTIONAL: After the 41C displays its move, punish it.

 

[E]

AAAIIII...

6

To signify that you can't move

0

[R/S]

I WIN

7

To start a new game with the same player first and punishments remembered.

 

[A]

READY (or)

 

 

 

 

( ) to ( )

  Go to step 4

8

To start a new game with a different player first and/or forgetting punishments go to step 2.

 

 

 

Example

   Keystrokes:          Display:
[XEQ] [ALPHA] SIZE 
[ALPHA] 014
[XEQ] [ALPHA] 
MACHINE [ALPHA]	        SEED?
.1111111111 [R/S]       8 to 5
1.5 [R/S]               7 to 4
(A bad move; therefore, 
punish)
[E]                     AAAIIII...
5.8 [R/S]               YOU WIN

Start a new game with the 41C remembering its
punishment.

[A]                     8 to 5
1.5 [R/S]               7 to 5
3.5 [R/S]               9 to 5
0 [R/S]                 I WIN

The Program

LINE  KEYS
 01 <>LBL "MACHINE"
 02  XEQ 01              Machine first
 03  8388607
 04  STO 01
 05  3139583
 06  STO 02
 07  34314
 08  STO 03
 09  SF 05
 10  GTO A
 11 <>LBL "HUMAN"
 12  XEQ 01              Human first
 13  16777215
 14  STO 01
 15  16756735
 16  STO 02
 17  524413
 18  STO 03
 19  CF 05
 20 <>LBL A
 21  SF 09
 22  SF 08               Start game
 23  9503
 24  STO 10
 25  .8596
 26  STO 06
 27  1
 28  FS? 05
 29  GTO 20
 30  "READY"
 31  AVIEW
 32  GTO 30
 33 <>LBL 01
 34  SF 27               Initialize
 35  CF 07
 36  CLRG
 37  "SEED?"
 38  RCL 00
 39  PROMPT
 40  STO 00
 41  RTN
 42 <>LBL 30
 43  STOP                Get a human move
 44  "I WIN"
 45  X=0?
 46  PROMPT
 47  FC?C 08
 48  GTO 00
 49  CF 07
 50  3.6
 51  FS? 05
 52  CHS
 53  X=Y?
 54  SF 07
 55  RDN
 56  1.4
 57  FC? 05
 58  CHS
 59  X=Y?
 60  SF 07
 61  RDN
 62  1.5
 63  X=Y?
 64  SF 07
 65  RDN
 66 <>LBL 00
 67  CF 09
 68  STO 13
 69  FRC
 70  .7
 71  X<=Y?
 72  GTO 26
 73  RCL 13
 74  XEQ 50
 75  INT               From
 76  STO 11
 77  LASTX
 78  FRC
 79  10
 80  *
 81  STO 12            To
 82  CF 06
 83  XEQ 21
 84  .9
 85  STO 13
 86  FS? 05
 87  GTO 22
 88  3185.848596
 89  XEQ 23            Human move first boards and responses
 90  7397.7475
 91  XEQ 23
 92  1316.417596
 93  XEQ 23      
 94  1142.845396
 95  XEQ 23
 96  2531.759596
 97  XEQ 23
 98  1023.848586
 99  XEQ 23
100  6758.515286
101  XEQ 23
102  7163.9586
103  XEQ 23
104  2720.4142
105  XEQ 23
106  1131.8475
107  XEQ 23
108  818.9596
109  XEQ 23
110  6650.9596
111  XEQ 23
112  992.96
113  XEQ 23
114  677.4152
115  XEQ 23
116  369.75
117  XEQ 23
118  600.4186
119  XEQ 23
120  384.8463
121  XEQ 23
122  693.4152
123  XEQ 23
124  461.5263
125  XEQ 23
126  569.419596
127  XEQ 23
128  411.8452
129  XEQ 23
130  195.5286
131  XEQ 23
132  585.4175
133  XEQ 23
134  137.9563
135  XEQ 23
136  GTO 25
137 <>LBL 22
138  9503.8596         Machine moves first boards and responses
139  XEQ 23
140  7341.748586
141  XEQ 23
142  7449.7475
143  XEQ 23
144  3237.848562
145  XEQ 23
146  8957.7451
147  XEQ 23
148  8849.9596
149  SF 09
150  XEQ 23
151  CF 09
152  6.9
153  STO 13
154  8849.7475
155  XEQ 23
156  6687.7475
157  XEQ 23
158  855.7475
159  XEQ 23
160  1194.845253
161  XEQ 23
162  2583.756263
163  XEQ 23
164  6702.63
165  XEQ 23
166  1260.41
167  XEQ 23
168  1368.7541
169  XEQ 23
170  6887.9596
171  XEQ 23
172  2783.414295
173  XEQ 23
174  6995.5152
175  XEQ 23
176  1179.5253
177  XEQ 23
178  2286.7475
179  XEQ 23
180  2270.9596
181  XEQ 23
182  2594.96
183  XEQ 23
184  621.4163
185  XEQ 23
186  432.52
187  XEQ 23
188  GTO 25
189 <>LBL 23
190  ISG 13
191  INT               Check to see if correct board
192  RCL 10
193  X!=Y?
194  RTN
195  LASTX
196  FRC
197  STO 06
198  RCL 13
199  INT
200 <>LBL 20           Move
201  STO 08
202  RCL 04
203  STO 09
204  RCL 05
205  STO 07
206  2
207  RCL 08
208  Y^X
209  STO 05
210  3
211  STO 13
212  RCL 00
213  9821
214  *
215  .211327
216  +                 Random number generator
217  FRC
218  STO 00
219  *
220  1
221  +
222  INT
223  STO 04
224 <>LBL 02
225  3
226  RCL 04            Move loop
227  1
228  +
229  X>Y?
230  1
231  STO 04
232  X<> 13
233  RCL IND 13
234  X<>Y
235  X<> 13
236  RDN
237  RCL 05
238  /
239  FRC
240  .5
241  X<=Y?
242  GTO 04
243  DSE 13
244  GTO 02
245  RCL 07
246  STO 05
247  STO 04
248  FS? 08
249  CF 09
250  FS? 09
251  RTN
252 <>LBL 25
253  "NO MOVE"         No move possible
254  AVIEW
255  PSE
256 <>LBL 26
257  "YOU WIN"
258  AVIEW
259  STOP
260 <>LBL 04
261  RCL 04
262  1                 Convert machine's move to board notation
263  X!=Y?
264  CF 08
265  -
266  2
267  *
268  10^X
269  RCL 06
270  *
271  FRC
272  10
273  *
274  INT
275  STO 11
276  LASTX
277  FRC
278  10
279  *
280  INT
281  STO 12
282  SF 06
283  XEQ 21
284  3
285  RCL 12
286  X>Y?
287  GTO 00            41C win
288  AVIEW
289  BEEP
290 <>LBL 00
291  RCL 11
292  RCL 12            41C move display and board update
293  10
294  /
295  +
296  XEQ 50
297  FIX 0
298  CF 29
299  CLA
300  INT
301  ARCL X
302  "|- TO "
303  LASTX
304  FRC
305  10
306  *
307  ARCL X
308  AVIEW
309  GTO 30
310 <>LBL 50
311  FC? 07
312  RTN               Get mirror image move
313  STO 06
314  INT
315  1
316  -
317  3
318  /
319  INT
320  5
321  +
322  XEQ IND X
323  RCL 06
324  -
325  RTN
326 <>LBL 05
327  5
328  RTN
329 <>LBL 06
330  10.4
331  RTN
332 <>LBL 07
333  17
334  RTN
335 <>LBL 21
336  RCL 10
337  3                 Update board
338  ENTER^
339  10
340  ENTER^
341  RCL 12
342  -
343  Y^X
344  /
345  FRC
346  3
347  *
348  INT
349  CHS
350  1
351  FS? 06
352  ST+ X
353  +
354  3
355  ENTER^
356  9
357  ENTER^
358  RCL 12
359  -
360  Y^X
361  *
362  3
363  ENTER^
364  9
365  RCL 11
366  -
367  Y^X
368  1
369  FS? 06
370  ST+ X
371  *
372  -
373  ST+ 10
374  RTN
375 <>LBL E
376  RCL 04            Punish
377  X<> 13
378  RCL 05
379  2
380  /
381  ST- IND 13
382  RDN
383  X<> 13
384  "AAAIIII..."
385  AVIEW
386  GTO 30
387  .END.

Register Use

R00  Seed
R01  Possible moves
R02  Possible moves
R03  Possible moves
R04  Trial move
R05  Used
R06  Used
R07  Used
R08  Current Move
R09  Last move
R10  Board
R11  From
R12  To
R13  Counter

Flags

05  41C first / Human first
06  41C's move / Human's move
07  Mirror image / Normal game
08  First move
09  Used

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall