Post Reply 
Newbie Question: HP-55 Conditional Tests
07-12-2019, 06:24 PM
Post: #1
Newbie Question: HP-55 Conditional Tests
Hey everyone, I have some questions. I am very new to the world of HP calculators and RPN and I'm trying to make some simple games to get myself started. On rskey.org there is are two games for the HP-55 (my current calculator) and one of those is Nimb, or Nim. The version there is for one player and is against a computer opponent, so I thought I would make a two player version that I could play with a friend. For those who don't know how the game works, basically you draw from a pile of 15 sticks and try to make your opponent draw the last one. Okay, with that out of the way, here was my first piece of code:

1. FIX
2. 0
3. 1
4. 5
5. R/S
6. -
7. GTO 05

Pretty basic right? All this code does is display 15 and allow me to subtract however much I want from it by keying in a number and hitting R/S. This technically could be the game, but I wanted to polish it a bit. The biggest problem with this little program is that the game never ends, and you can keep subtracting sticks past 0. I thought that I would make the screen say "lose" or something when the game was over, and from there it could be reset. This was the part I was stuck on though, because it requires a conditional test and thats not a concept I completely get yet. This was my next piece of code; before making it run, I key in STO 3507 1 (or "Lose" upside down). All I have are a few examples to go off of, and I clearly didn't seem to understand why they work there but not here.
1. FIX
2. 0
3. 1
4. 5
5. R/S
6. -
7. 0
8. f
9. X < = Y (-12)
10. RDN
11. GTO 05
12. RCL
13. 1
14. GTO 00

I thought that this would act like the previous program did, allowing me to subtract from 15, but that when the number of sticks became less than or equal to 0 the "lose" message would be displayed. That's not the case; usually it lets me hit a number but then goes straight to "lose." Any advice? How exactly do the conditional tests work? How are X and Y even established to begin with? Hopefully I don't sound too dumb with this, but hey, we all gotta start somewhere.
Find all posts by this user
Quote this message in a reply
07-12-2019, 08:03 PM
Post: #2
RE: Newbie Question: HP-55 Conditional Tests
I don’t quite understand what your step 0 is, but ‘the test is opposite to what it needs to be. X had 0 and y has the running total so the branch to 12 (“lose”) happens when zero is less than (or equal to) the total. Step 10 seems superfluous as well, and your current version, even if it branched to where you wanted to, would leave 0 exposed and not the running total, and that 0 would be automatically lifted by the user entry so the succeeding subtraction subtracts the user’s entry from 0, not the running total.

Easiest fix is to put 0 followed by enter between you current steps 2 and 3 and remove your current steps 7 and 10.mthis should fix both problems (but caveat emptor: I didn’t test it; fixing solely by code reading is always dangerous, even fo most experts!)-kby

(07-12-2019 06:24 PM)snoman003 Wrote:  Hey everyone, I have some questions. I am very new to the world of HP calculators and RPN and I'm trying to make some simple games to get myself started. On rskey.org there is are two games for the HP-55 (my current calculator) and one of those is Nimb, or Nim. The version there is for one player and is against a computer opponent, so I thought I would make a two player version that I could play with a friend. For those who don't know how the game works, basically you draw from a pile of 15 sticks and try to make your opponent draw the last one. Okay, with that out of the way, here was my first piece of code:

1. FIX
2. 0
3. 1
4. 5
5. R/S
6. -
7. GTO 05

Pretty basic right? All this code does is display 15 and allow me to subtract however much I want from it by keying in a number and hitting R/S. This technically could be the game, but I wanted to polish it a bit. The biggest problem with this little program is that the game never ends, and you can keep subtracting sticks past 0. I thought that I would make the screen say "lose" or something when the game was over, and from there it could be reset. This was the part I was stuck on though, because it requires a conditional test and thats not a concept I completely get yet. This was my next piece of code; before making it run, I key in STO 3507 1 (or "Lose" upside down). All I have are a few examples to go off of, and I clearly didn't seem to understand why they work there but not here.
1. FIX
2. 0
3. 1
4. 5
5. R/S
6. -
7. 0
8. f
9. X < = Y (-12)
10. RDN
11. GTO 05
12. RCL
13. 1
14. GTO 00

I thought that this would act like the previous program did, allowing me to subtract from 15, but that when the number of sticks became less than or equal to 0 the "lose" message would be displayed. That's not the case; usually it lets me hit a number but then goes straight to "lose." Any advice? How exactly do the conditional tests work? How are X and Y even established to begin with? Hopefully I don't sound too dumb with this, but hey, we all gotta start somewhere.
Find all posts by this user
Quote this message in a reply
07-12-2019, 09:22 PM (This post was last modified: 07-12-2019 10:28 PM by snoman003.)
Post: #3
RE: Newbie Question: HP-55 Conditional Tests
Okay, just tried it. It doesn't work if it's placed between steps 2 and 3; for some reason subtraction stops working altogether. However, it works when FIX 0 is removed entirely and left as a manual action before the game starts, which I can live with. I've got one further question though-- where exactly does the calculator draw from to pull X and Y values? I think once I understand how thats done, conditional tests should be much easier to use. I understand that it's something to do with the stack, but again, it's kind of hard to find learning resources for this stuff. Never was the quickest with programming.
Find all posts by this user
Quote this message in a reply
07-12-2019, 09:44 PM
Post: #4
RE: Newbie Question: HP-55 Conditional Tests
Awesome! Here's the new code for anyone who's got a friend around:
1. 0
2. ENTER
3. 1
4. 5
5. R/S
6. -
7. f
8. X <= Y (-10)
9. GTO 05
10. RCL
11. 1
12. GTO 00

And of course, when running the game, FIX 0 and STO 3507 1. Thanks for the help, kby! Just joined today and already got the help I've been needing. Here's to much more of that!
Find all posts by this user
Quote this message in a reply
07-12-2019, 10:38 PM (This post was last modified: 07-12-2019 10:41 PM by teenix.)
Post: #5
RE: Newbie Question: HP-55 Conditional Tests
(07-12-2019 06:24 PM)snoman003 Wrote:  How exactly do the conditional tests work? How are X and Y even established to begin with? Hopefully I don't sound too dumb with this, but hey, we all gotta start somewhere.

For X<=Y or X=Y tests...

Quote from the manual...

(A) If the answer is YES, the program branches to the line specified.
(B) If the answer is NO, program execution continues sequentially.

X = 9
Y = 0

if X<=Y 08 ; if X <=Y go to line 08
9 is not less than or equal to 0 so (B), program continues from next program line

X = 0
Y = 9
if X<=Y 08 ; if X <=Y go to line 08
0 is less than 9 so (A), program continues from program line 08

In your code...

Say you enter 8 as a first value, then R/S

15 - 8 = 7 remaining

You then put 0 in X, which puts the 7 in Y
Now you do the test

if X<=Y 12 ; if X <=Y go to line 12
0 is less than 7 so (A), program continues from program line 12

3507 is recalled from storage [0] and the program stops

This is not what you want however.

Below is modified code which works

8. X<>Y ; now puts 0 in Y, and the 7 in X
9. f
10. X <= Y (-12) ; 7 is not < 0, (B) continue
11. GTO 05 ; for answer = 7, next line to execute
12. RCL
13. 1
14. GTO 00

cheers

Tony
Find all posts by this user
Quote this message in a reply
07-12-2019, 11:08 PM
Post: #6
RE: Newbie Question: HP-55 Conditional Tests
Hm-- it's not working correctly, Tony. The program I listed states 3507 when the sticks reach 0, whereas the modified steps you showed kind of break the subtraction for some reason. Not sure why that is, but thank you for the explanation regardless!
Find all posts by this user
Quote this message in a reply
07-12-2019, 11:30 PM
Post: #7
RE: Newbie Question: HP-55 Conditional Tests
(07-12-2019 11:08 PM)snoman003 Wrote:  Hm-- it's not working correctly, Tony. The program I listed states 3507 when the sticks reach 0, whereas the modified steps you showed kind of break the subtraction for some reason. Not sure why that is, but thank you for the explanation regardless!

Oops, I hope I go the concept right.

I press R/S to initiate the game, then enter a value and press R/S again.

If the result is > 0 continue game
If result <= 0 display 3507 and stop
The image shows the code as run on my HP55 emulator and is waiting for the first input.
The inlay shows the display when the entered value resulted in a zero answer.

cheers

Tony


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
07-12-2019, 11:35 PM
Post: #8
RE: Newbie Question: HP-55 Conditional Tests
Hm, interesting. I'm not sure what exactly isn't working on mine then, since I've tried the code multiple times. You're right with the concept, so idk. At least I've got some kind of working version. Thanks again
Find all posts by this user
Quote this message in a reply
07-12-2019, 11:41 PM
Post: #9
RE: Newbie Question: HP-55 Conditional Tests
(07-12-2019 09:22 PM)snoman003 Wrote:  Okay, just tried it. It doesn't work if it's placed between steps 2 and 3; for some reason subtraction stops working altogether. However, it works when FIX 0 is removed entirely and left as a manual action before the game starts, which I can live with. I've got one further question though-- where exactly does the calculator draw from to pull X and Y values? I think once I understand how thats done, conditional tests should be much easier to use. I understand that it's something to do with the stack, but again, it's kind of hard to find learning resources for this stuff. Never was the quickest with programming.

If you need a HP-55 emulator to see what happens internally try...

http://www.teenix.org/

Well done for sorting the problem.

cheers

Tony
Find all posts by this user
Quote this message in a reply
07-13-2019, 02:28 AM
Post: #10
RE: Newbie Question: HP-55 Conditional Tests
(07-12-2019 09:22 PM)snoman003 Wrote:  Okay, just tried it. It doesn't work if it's placed between steps 2 and 3; for some reason subtraction stops working altogether. However, it works when FIX 0 is removed entirely and left as a manual action before the game starts, which I can live with. I've got one further question though-- where exactly does the calculator draw from to pull X and Y values? I think once I understand how thats done, conditional tests should be much easier to use. I understand that it's something to do with the stack, but again, it's kind of hard to find learning resources for this stuff. Never was the quickest with programming.

OK. I hauled out my -55:
00.
01. 24 FIX
02. 00 0
03. 00 0
04. 41 Enter
05. 01 1
06. 05 5
07. 84 R/S
08. 51 –
09. 31 f
10. – 12 x<y
11. – 07 GTO 7
12. 34 RCL
13. 01 1
14. – 00 GTO 00

There was an additional adjustment of the GTO target in line 11. The target of the GTO that is part of the conditional doesn’t actually change, but only by coincidence (same number of steps at beginning).-kby
Find all posts by this user
Quote this message in a reply
07-13-2019, 02:42 AM
Post: #11
RE: Newbie Question: HP-55 Conditional Tests
Thanks, that's for sure the definitive version at this point.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)