Nimb Game for the HP-15C

Description

Origin: HP-34C APPLICATIONS, October 1980, p. 48

The Object of the game is to get your opponent take the last match stick.

The game of Nimb begins with a collection of N objects, or as the calculator plays it, with the positive number N. Each player alternately subtracts one, two, or more from the total until only one‘is left. The player forced to take the last one loses.

To begin the game you specify the maximum number that can be taken in a single move. Then you tell the calculator how many objects you wish to start with (i.e., the value of N).

After each move the machine will display the remaining total. A negative sign indicates that it is the player‘s move next, while a positive display
indicates that it is the HP-15C’s move.

As the challenger you are allowed to make the ?rst move. It is possible for you to win, but of course the HP-15C is a master player: it will not let you make an error and win. If you cheat by taking more than the specified limit the calculator will catch you and force you to repeat the move.

You can play an almost endless set of games, because you set the rules of each game with the A and B function keys.

This program is based on an HP-25 program by James L. Horn.

Example 1:

Starting with 15 objects, with a maximum allowable move of 3, play Nimb with the HP-15C.

3 A : For this game, players can take a maximum of 3 sticks per move
1 5 B :Start this game with 15 sticks on the pile
2 R/S : You pick up 2 sticks, the Calculator picks 1 leaving -12
3 R/S : You pick 3 sticks, the Calculator picks 1 stick leaving -8
3 R/S : You pick up 3 sticks, the Calculator picks 1 leaving -4
3 R/S : You pick up 3 sticks, leaving the Calculator to take the last one

Displays 3507.1 I LOSE upside down. You win the Calculator loses

Example 2:

3 A → 3.
1 5 B → -15. (Ready)
3 R/S → 12. (Player takes 3)
R/S → -9. (HP-15C takes 3)
2 R/S → 7. (Player takes 2)
R/S → -5. (HP-15C takes 2)
3 R/S → 3. (Player takes 3)
R/S → -1. (HP-15C takes 1)
1 R/S → 55178. (Player takes last one and loses)

Turn calculator upside down for message: BLISS

Program Resources

Labels

Name Description
 A Sets the maximum number of sticks you can take in each move.
 B Sets the number of sticks on the pile to start with.
 0 # Check validity of player's move, and compute Calculator's move.
 1 # Game Over (Display Win, or Lose Message)
 2 # Check to see if Player Won.
 4 # Display Sticks left on pile (Ready for Player's Move)

Storage Registers

Name Description
 0 Total (Pile)
 1 Max Grab per move+1
 2 I.LOSE (upside down Calculator loses You win)
 3 BLISS (upside down Calculator wins You lose)

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000 022 31 R/S 044 44,30, 0 STO 0
001 42,21,11 f LBL A 023 42,21,12 f LBL B 045 45 0 RCL 0
002 42, 7, 0 f FIX 0 024 42, 7, 0 f FIX 0 046 42 31 f PSE
003 44 0 STO 0 025 44 0 STO 0 047 1 1
004 1 1 026 42,21, 4 f LBL 4 048 30
005 40 + 027 16 CHS 049 45 1 RCL 1
006 44 1 STO 1 028 31 R/S 050 10 ÷
007 3 3 029 40 + 051 42 44 f FRAC
008 5 5 030 43,30, 2 g TEST x<0 052 45 1 RCL 1
009 0 0 031 22 0 GTO 0 053 20 ×
010 7 7 032 45 3 RCL 3 054 43 20 g x=0
011 48 . 033 22 1 GTO 1 055 1 1
012 1 1 034 42,21, 0 f LBL 0 056 44,30, 0 STO 0
013 44 2 STO 2 035 43 36 g LSTΧ 057 42,21, 2 f LBL 2
014 5 5 036 1 1 058 45 0 RCL 0
015 5 5 037 43,30, 7 g TEST x>y 059 43,30, 0 g TEST x≠0
016 1 1 038 22 2 GTO 2 060 22 4 GTO 4
017 7 7 039 33 R⬇ 061 45 2 RCL 2
018 8 8 040 45 1 RCL 1 062 42, 7, 1 f FIX 1
019 44 3 STO 3 041 43 10 g x≤y 063 22 1 GTO 1
020 45 0 RCL 0 042 22 2 GTO 2
021 42,21, 1 f LBL 1 043 34 x↔y