The Museum of HP Calculators

# Snakes and Ladders for the HP-41

This program is Copyright © 2007 by Jean-Marc Baillard and is used here by permission.

This program is supplied without representation or warranty of any kind. Jean-Marc Baillard 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

-You and the HP-41 are on square#0
-The 2 players alternately roll 2 dice. ( Flag F01 is set if it's your turn to play )
-If the dice are D1 D2, the player on square S moves forward on square S+D1+D2
-The snakes and the ladders may appear at random on every square#S provided  1 < S < 100
-When a snake appears, you move back. If a ladder appears, you move forward.
-Ladders are long near square#1, short near square#99
-Snakes are short ------------- ,  long ---------------
-The winner is the first one who reaches ( or exceeds ) square#100

Program Listing

Data Registers:           •  R00 = r = random numbers                          ( Register R00 is to be initialized before executing "SNLD" )
R01 thru R05:  temp

Flags:    F29 & F01   when F01 is set, it's your turn to play:  press any key to roll the dice
when F01 is clear, the HP-41 is playing.
Subroutines: /

01  LBL "SNLD"
02  " 00/00"
03  AVIEW
04  CLX
05  STO 01
06  STO 02
07  FIX 0
08  CF 01
09  CF 29
10  XEQ 06
11  4
12  X>Y?
13  SF 01
14  LBL 01
15  FS? 01
16  GETKEY               ( lines 15-16 are actually almost unuseful! )
17  XEQ 06
18  STO 03
19  XEQ 06
20  STO 04
21  +
22  LBL 02
23  FS? 01
24  ST+ 01
25  FC? 01
26  ST+ 02
27  COS
28  COS
29  COS
30  RCL 01
31  10
32  " "                          one space
33  X>Y?
34  "~0"                       append 0
35  ARCL 01
36  "~/"                        append /
37  RCL 02
38  X<Y?
39  "~0"                       append 0
40  ARCL 02
41  "~  "                       append  space  space
42  ARCL 03
43  "~+"                       append +
44  ARCL 04
45  AVIEW
46  FS? 01
47  RCL 01
48  STO 05
49  99
50  X<Y?
51  GTO 07
52  SIGN
53  X=Y?
54  GTO 03
55  RCL 00
56  R-D
57  FRC
58  STO 00
59  .8                           there is a snake if  r > 0.8      where  r is the content of register R00
60  X<Y?
61  GTO 04
62  6
63  /                             there is a ladder if r < 0.8/6    change lines 59-62-63  if you prefer more ( or less ) snakes and/or ladders.
64  X>Y?
65  GTO 05
66  LBL 03
67  FC?C 01
68  SF 01
69  GTO 01
70  LBL 04
71  RCL 05
72  3
73  /
74  1
75  +
76  INT
77  CHS
78  " SNAKE"
79  AVIEW
80  GTO 02
81  LBL 05
82  15
83  RCL 05
84  7
85  /
86  -
87  INT
88  1
89  +
91  AVIEW
92  GTO 02                   a three-byte GTO
93  LBL 06
94  RCL 00
95  R-D
96  FRC
97  STO 00
98  6
99  *
100  1
101  +
102  INT
103  RTN
104  LBL 07
105  FS? 01
106  " YOU WIN"
107  FC?C 01
108  " HP-41 WINS"
109  FIX 4
110  SF 29
111  AVIEW
112  END

( 210 bytes / SIZE 006 )

Example:    5  STO 00   XEQ "SNLD"

" 00/00"                  and flag F01 is set: it's your turn to play, press any key
" 04/00   3+1"         the dice are 3 & 1 so you move on square#04. Flag F01 is cleared so the HP-41 roll the dice
" 04/07   6+1"         -----------  6 & 1 the HP-41 move on square#07...
" SNAKE"              but there is a snake, the calculator moves back...
" 04/04   6+1"         ... on square#04...
" 04/19  6+1"          ... on square#19 and flag F01 is set again: you press a key
" 13/19  3+6"          the dice are 3 & 6 so you move on square#13 ... and so forth ...

-The HP-41 displays  " S1/S2  D1+D2"    where  S1 is your square,  S2 is HP-41's square,  D1+D2 are the 2 dice.

-Actually, the game is completely determined by the seed you've stored in register R00
-If you want to influence the chance, add  FS? 01  ST+ 00  after line 16:
the keys you'll press will modify the random numbers in register R00.

-Do not store a number like PI in R00: the sequence of "random" numbers would be 0 0 0 0  ....
( or change the random number generator lines 94 to 97 )