12c platinum Bagels game listing Message #9 Posted by Gene Wright on 22 Sept 2005, 4:00 p.m., in response to message #1 by Gene
Here it is...all 258 lines of it. PLEASE feel free to help correct any mistakes or suggest improvements. My goal is not to have any programming pride left :-) but to have a good workable Bagels game for the 12cp.
Couple of notes: 1) the g prefix is not included for the comparison tests, the x^2 and SQRT (square root) functions, and not for the FRAC and INT functions. ROLL DOWN is pretty self explanatory. Line 62 is "gold shift 1" to set the display to 1 decimal point.
The steps which compare each digit of the secret and guessed number work like this: I subtract the digits which will either give me a 0, or -3 through -1 or a 3 through 1. I then take the absolute value by squaring and then square rooting the result. That means I have a 0 (indicating a matched number) or a positive 1, 2, or 3. I then put a 1 on the stack and test this 1 to the previous result (which is either a 0, 1, 2, or 3 in the Y-register). If this 1 is <= the number in Y, I do not have a match and I replace the 1 with a 0. Otherwise, the 1 stays. I then add the number in X (which is a 1 if it was a match or a 0 if it was not a match) to the appropriate counter for guesses (Memory 0 is for correct guesses and 1 is for incorrect).
Memory usage: 0 is the correct digit counter, 1 is the wrong place but in the secret number counter, 2 through 5 hold one digit of the secret number (don't peek!), 6 through 9 hold one digit of the entered guess number, memory .0 holds the seed, memory .1 holds the input guess number as a 4 digit value (which is destroyed as the digits are separated), and memory .2 holds the guess count.
How to use: 1) Key in a decimal seed for each game and press GTO 000 then R/S. The calculator will generate the secret number and stop displaying 0.0. 2) Enter a 4 digit guess and press R/S. 3) The calculator will return a number of the form X.Y, where X is the count of digits in your guess that are in right place in the secret number and Y is the count of digits in your guess that occur in the secret number, but are in the wrong location. 4) Continue entering 4 digit guesses and pressing R/S until you have guessed the secret number. 5) When you guess the number correctly, the display will show 4.0. The number of guesses you took is in the Y-register and can be viewed by pressing X<>Y.
Example game:
1) Seed 0.123456789 GTO 000 R/S --- calculator shows 0.0 in about 3-4 seconds.
2) Guess 1234 R/S --- calculator shows 2.1 in about 5-6 seconds. We have 2 digits correctly guessed and 1 digit right but in the wrong spot.
3) Guess 9134 R/S --- calculator shows 0.3, so we have 3 numbers right but in the wrong spot.
4) Guess 1263 R/S --- calculator shows 3.0, so we have 3 numbers in the right spots.
5) Guess 1293 R/S --- calculator shows 4.0 -- only took 4 guesses. That's good!
For a new game, enter a new seed, press GTO 000 and then R/S.
Note: The game will generate a secret number that may have duplicate digits.
Known issues: Of course, as I typed up the instructions, I noticed a couple of things. 1) If the secret number is 2222 and you guess 2222, the display does not show 4.0, but 5.2 of all things. Why? I'm thinking through that one. 2) If the secret number is 1292 and you guess 1294, you'll get 3.1 shown, since the "2" you guess will be correct for digit 2 and in the wrong place for digit 4 of the secret number. I'm sure this could be fixed (if desired), but at what step expense?
So, there you have it. I'd like for this to be viewed as the start of a few more games for the 12cp. Improvements are welcomed! :-)
1 STO . 0 55 STO 7 109 RCL 6 163 RCL 7 217 RCL 9
2 9 56 STO 8 110 RCL 3 164 RCL 5 218 RCL 3
3 9 57 STO 9 111 - 165 - 219 -
4 7 58 STO . 1 112 X^2 166 X^2 220 X^2
5 X 59 STO . 2 113 SQRT 167 SQRT 221 SQRT
6 FRAC 60 STO 0 114 1 168 1 222 1
7 STO . 0 61 STO 1 115 X<=Y 169 X<=Y 223 X<=Y
8 9 62 f 1 116 0 170 0 224 0
9 X 63 R/S 117 STO + 1 171 STO + 1 225 STO + 1
10 1 64 STO . 1 118 RCL 6 172 RCL 8 226 RCL 9
11 + 65 1 119 RCL 4 173 RCL 2 227 RCL 4
12 INT 66 0 120 - 174 - 228 -
13 STO 2 67 / 121 X^2 175 X^2 229 X^2
14 RCL . 0 68 ENTER 122 SQRT 176 SQRT 230 SQRT
15 9 69 INT 123 1 177 1 231 1
16 9 70 STO . 1 124 X<=Y 178 X<=Y 232 X<=Y
17 7 71 - 125 0 179 0 233 0
18 X 72 1 126 STO + 1 180 STO + 1 234 STO + 1
19 FRAC 73 0 127 RCL 6 181 RCL 8 235 RCL 9
20 STO . 0 74 X 128 RCL 5 182 RCL 3 236 RCL 5
21 9 75 STO 9 129 - 183 - 237 -
22 X 76 RCL . 1 130 X^2 184 X^2 238 X^2
23 1 77 1 131 SQRT 185 SQRT 239 SQRT
24 + 78 0 132 1 186 1 240 1
25 INT 79 / 133 X<=Y 187 X<=Y 241 X<=Y
26 STO 3 80 ENTER 134 0 188 0 242 0
27 RCL . 0 81 INT 135 STO + 1 189 STO + 1 243 STO + 0
28 9 82 STO . 1 136 RCL 7 190 RCL 8 244 RCL . 2
29 9 83 - 137 RCL 2 191 RCL 4 245 1
30 7 84 1 138 - 192 - 246 +
31 X 85 0 139 X^2 193 X^2 247 STO . 2
32 FRAC 86 X 140 SQRT 194 SQRT 248 RCL 1
33 STO . 0 87 STO 8 141 1 195 1 249 1
34 9 88 RCL . 1 142 X<=Y 196 X<=Y 250 0
35 X 89 1 143 0 197 0 251 /
36 1 90 0 144 STO + 1 198 STO + 0 252 RCL 0
37 + 91 / 145 RCL 7 199 RCL 8 253 +
38 INT 92 ENTER 146 RCL 3 200 RCL 5 254 0
39 STO 4 93 INT 147 - 201 - 255 STO 1
40 RCL . 0 94 STO 6 148 X^2 202 X^2 256 STO 0
41 9 95 - 149 SQRT 203 SQRT 257 ROLL DOWN
42 9 96 1 150 1 204 1 258 GTO 063
43 7 97 0 151 X<=Y 205 X<=Y
44 X 98 X 152 0 206 0
45 FRAC 99 STO 7 153 STO + 0 207 STO + 1
46 STO . 0 100 RCL 6 154 RCL 7 208 RCL 9
47 9 101 RCL 2 155 RCL 4 209 RCL 2
48 X 102 - 156 - 210 -
49 1 103 X^2 157 X^2 211 X^2
50 + 104 SQRT 158 SQRT 212 SQRT
51 INT 105 1 159 1 213 1
52 STO 5 106 X<=Y 160 X<=Y 214 X<=Y
53 0 107 0 161 0 215 0
54 STO 6 108 STO + 0 162 STO + 1 216 STO + 1
|