Cyber Tennis Game for HP-41C
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.