Label |
A |
001 |
LBL A |
|
A |
002 |
0 |
Start count of required moves at 0. |
A |
003 |
STO C |
Set bottom to 0. |
A |
004 |
STO B |
Set the display equations as text flag. |
A |
005 |
SF 10 |
Display title and other info. |
A |
006 |
NUMBER GUESS |
|
A |
007 |
PSE |
|
A |
008 |
FROM 0 TO TOP |
|
A |
009 |
PSE |
Input T, T is the Top of the range. |
A |
010 |
INPUT T |
Select a random number between B and T Rand generates X where 0 < X < 1 and since we are truncating we need top to be 1 higher. In other words if our range is 0 to 10 (T+1) - B = 11, if rand returns .00..01 our output is close to 0 and will be 0 once truncated. If rand returns .999..9 our output will be near 11 and will be 10 when truncated therefor all our numbers will be represented with nearly equal frequency. |
A |
011 |
RCL T |
A |
012 |
1 |
A |
013 |
+ |
A |
014 |
RCL B |
A |
015 |
- |
A |
016 |
RANDOM |
A |
017 |
* |
A |
018 |
IP |
|
A |
019 |
RCL B |
Re-adjust for B back to correct range. |
A |
020 |
+ |
Store the number to guess. |
A |
021 |
STO N |
|
A |
022 |
CLSTK |
|
A |
023 |
GUESS |
|
A |
024 |
PSE |
Increment the number of guesses. |
A |
025 |
1 |
|
A |
026 |
STO+ C |
Get the players guess. |
A |
027 |
INPUT G |
|
A |
028 |
RCL N |
If the random number was equal to thier guess: |
A |
029 |
x=y? |
Goto the winning line |
A |
030 |
GTO A036 |
If the random number was less than thier guess: |
A |
031 |
x<y? |
Execute the 'TRY LOWER' routine. |
A |
032 |
XEQ A045 |
If the random number was greater than thier guess: |
A |
033 |
x>y? |
Execute the 'TRY HIGHER' routine. |
A |
034 |
XEQ A041 |
Then let them guess again. |
A |
035 |
GTO A025 |
|
A |
036 |
YOU WIN |
Clear the mess in the stack |
A |
037 |
CLSTK |
Reset the equation display flag. |
A |
038 |
CF 10 |
Drop the number of tries on the stack |
A |
039 |
RCL C |
Return from the program |
A |
040 |
RTN |
The 'TRY HIGHER' and 'TRY LOWER' subroutines are seperate from main program flow because the program needs to clear the stack before showing the messages if this doesn't happen the correct number will briefly flash on the screen before or after the pause is executed. Both of these subroutines just clear the stack display the appropriate message and then return to the main subroutine execution. |
A |
041 |
CLSTK |
A |
042 |
TRY HIGHER |
A |
043 |
PSE |
A |
044 |
RTN |
A |
045 |
CLSTK |
A |
046 |
TRY LOWER |
A |
047 |
PSE |
|
A |
048 |
RTN |
LN=203, CK=2819 |