Cyber Tennis Game for HP-41C
09-02-2017, 08:01 PM (This post was last modified: 09-05-2017 11:40 PM by Namir.)
Post: #1
 Namir Senior Member Posts: 1,083 Joined: Dec 2013
Cyber Tennis Game for HP-41C
The game assumes you are playing a 10-point match of cyber tennis. You play as many rounds until either you or the calculator wins 10 rounds. See instructions to play the game.

Memory Map

Code:
R00 = random number R01 = counter for player R02 = counter for calculat0r R03 = win count R04 = max range

HP-41C Listing

Code:
LBL "TENNIS" LBL a 0 STO 01 STO 02 10 STO 03 X^2 STO 04 LBL A        # main game routine RCL 01         RCL 03 X=Y?        # did the player win the game? GTO B RCL 02 X=Y?        # did the calculator win the game? GTO C RCL 00 "SEED?" FC? 00        # check flag 00 for no-prompt mode PROMPT        # prompt for next seed (optional) STO 00 XEQ 01        # get random integer for player XEQ 01        # get random integer for calculator X>Y?        # did the calculator win current round? GTO 02 X<>Y X>Y?        # did the player win the current round? GTO 03 "TIE" AVIEW         PSE        # no one won the current round GTO A LBL 02        # increment calculator wins 1 STO+ 02 "CALC:" ARCL 02 AVIEW PSE        # display calculator's winning GTO A LBL 03        # increment player's wins 1 STO+ 01 "YOU:" ARCL 01 AVIEW PSE        # display as player's number GTO A LBL B        # Player wins the game "YOU WIN" GTO 04 LBL C        # Calculator wins the game "YOU LOSE" LBL 04 BEEP PROMPT RTN LBL 01        # get random integer XEQ E RCL 04 * INT RTN LBL E        # PRNG function RCL 00 PI + 5 Y^X FRC STO 00 RTN

Games Instructions

1) Press [XEQ]"TENNIS or [shift][A] (in User Mode) to initialize the game.
2) The program stops to display current seed. You can alter this value or enter a new one. The new "seed" can be an integer, a fraction, or a number contains both.
3) Press [R/s]. The program determines who wins the current round:
A) If the player wins, the program pauses and displays "YOU:" followed by current total wins for the player.
B) If the calculator wins, the program pauses and displays "CALC:" followed by the current total wins for the calculator.
C) If no one wins the current round, the program pauses and displays "TIE".

4) Repeat steps 2 and 3. If the player wins, the program displays "YOU WIN". If the calculator wins, the program displays "YOU LOSE".

Note: You can set flag 00 to skip the "SEED?" prompt.
09-03-2017, 05:25 PM (This post was last modified: 09-03-2017 08:46 PM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Cyber Tennis Game for HP-41C
(09-02-2017 08:01 PM)Namir Wrote:  Note: You can set flag 00 to skip the "SEED?" prompt.

If this is the intended behaviour the FC? 00 test has to move down one step between "SEED?" and PROMPT.
The comment at LBL 02 says that a negative number is displayed. That's not correct, all output is positive.
LBL 01 generates a random integer between 0 and 99. This score is never displayed, so the routine can be completely removed and all calls replaced by XEQ E. This way also all references to R04 are obsolete. Since the probability of a tie then is near zero that part of the code can be removed as well. ;-)
The program does not set the display mode. At least a FIX 0 and preferably also a CF 29 in the initialization routine is recommended.

Dieter
09-05-2017, 02:59 PM
Post: #3
 Namir Senior Member Posts: 1,083 Joined: Dec 2013
RE: Cyber Tennis Game for HP-41C
(09-03-2017 05:25 PM)Dieter Wrote:
(09-02-2017 08:01 PM)Namir Wrote:  Note: You can set flag 00 to skip the "SEED?" prompt.

If this is the intended behaviour the FC? 00 test has to move down one step between "SEED?" and PROMPT.
The comment at LBL 02 says that a negative number is displayed. That's not correct, all output is positive.
LBL 01 generates a random integer between 0 and 99. This score is never displayed, so the routine can be completely removed and all calls replaced by XEQ E. This way also all references to R04 are obsolete. Since the probability of a tie then is near zero that part of the code can be removed as well. ;-)
The program does not set the display mode. At least a FIX 0 and preferably also a CF 29 in the initialization routine is recommended.

Dieter

09-05-2017, 04:59 PM
Post: #4
 Sylvain Cote Senior Member Posts: 2,129 Joined: Dec 2013
RE: Cyber Tennis Game for HP-41C
(09-05-2017 02:59 PM)Namir Wrote:  Edited listing's erroneous comments.

Hello Namir,

What Dieter was trying to convey in his first remark, was this piece of code
Code:
RCL 00 FC? 00        # check flag 00 for no-prompt mode "SEED?" PROMPT        # prompt for next seed (optional) STO 00

should be modified to
Code:
RCL 00 "SEED?" FC? 00        # check flag 00 for no-prompt mode PROMPT        # prompt for next seed (optional) STO 00

Best regards,

Sylvain
09-05-2017, 08:32 PM (This post was last modified: 09-06-2017 12:04 PM by Dieter.)
Post: #5
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Cyber Tennis Game for HP-41C
(09-05-2017 02:59 PM)Namir Wrote:  Edited listing's erroneous comments.

OK, but this does not change the way the program works, cf. Sylvain's explanation.

Anyway... as you may know from earlier posts I'm a big fan of short and effective code, especially in programs for calculators with their limited ressources. Below is my attempt at a very streamlined version of "tennis". Maybe you can try it and see how you like it. It requires just R0...R2 and 43 steps.

Code:
01  LBL"TENNIS" 02  RCL 00 03  "SEED?"         ; prompt for random seed 04  PROMPT          ; just press R/S to continue with the current seed 05  STO 00 06  LBL 01          ; new match starts here 07  CLX 08  STO 01          ; reset your score 09  STO 02          ; reset calculator's score 10  LBL 02          ; new round starts here 11  RCL 00 12  Pi 13  +               ; generate a pseudo random number 14  X^2 15  FRC 16  STO 00          ; X = 0...0,999999999 17  ST+ X           ; X = 0...1,999999998 18  SIGN            ; X = 1, L = 0...1,999999998 19  ST+ L           ; X = 1, L = 1...2,999999998 20  ST+ IND L       ; add 1 to R01 (your score) or R02 (calculator's score) 21  FIX 0 22  CF 29 23  "YOU: "         ; build score message 24  ARCL 01 25  "├ 41C: " 26  ARCL 02 27  FIX 4           ; on a 41CX or with an X-Func module you may use "RCLFLAG" before FIX 0  28  SF 29           ; and "STOFLAG" after ARCL 02 instead of these two lines 29  AVIEW           ; display scores 30  PSE 31  10 32  RCL IND L       ; has last updated score reached 10 points? 33  X<Y?            ; if still less 34  GTO 02          ; do another round 35  "YOU LOSE"      ; match finished, set "you lose" message first 36  RCL 02 37  RCL 01 38  X>Y?            ; if your score is higher than calculator's 39  "YOU WIN"       ; set "you win"  message 40  AVIEW 41  BEEP 42  RTN 43  GTO 01          ; press [R/S] for another match

The flag 0 skip of the seed prompt has been omitted as I think that simply pressing [R/S] instead is even easier than setting a flag manually. Also a seed input is not required in every single round but only once when the program starts.

Dieter
09-05-2017, 11:41 PM
Post: #6
 Namir Senior Member Posts: 1,083 Joined: Dec 2013
RE: Cyber Tennis Game for HP-41C
(09-05-2017 04:59 PM)Sylvain Cote Wrote:
(09-05-2017 02:59 PM)Namir Wrote:  Edited listing's erroneous comments.

Hello Namir,

What Dieter was trying to convey in his first remark, was this piece of code
Code:
RCL 00 FC? 00        # check flag 00 for no-prompt mode "SEED?" PROMPT        # prompt for next seed (optional) STO 00

should be modified to
Code:
RCL 00 "SEED?" FC? 00        # check flag 00 for no-prompt mode PROMPT        # prompt for next seed (optional) STO 00

Best regards,

Sylvain

Fixed the location of FC?00 command.
09-06-2017, 11:26 AM (This post was last modified: 09-06-2017 12:09 PM by Dieter.)
Post: #7
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Cyber Tennis Game for HP-41C
(09-05-2017 11:41 PM)Namir Wrote:  Fixed the location of FC?00 command.

Fine. But there still is one thing I do not understand: With flag 0 cleared program prompts for a seed in every single round of the match. Is there a special reason for this, or why don't you just put the seed prompt into the initialisation routine at LBL a so that it only appears when a new match is started – like in most other games programs? This also would make the whole flag 0 thing obsolete.

Just curious,

Dieter
 « Next Oldest | Next Newest »

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