************************************************************* Undercut by Ephraim Segerman ************************************************************* "Undercut" listings - 7700 upwards: Rules: You and the calculator each choose a number between 1 and 5. If the numbers are the same or different by more than one, then you and the calculator get the number of points you chose (eg. CPU 2, HUMAN 5, - calculator gets 2 points, you get 5). If the numbers are different by exactly one, then the player (human or calculator) who chose the lower number gets both sets of points and the one who chose the higher number gets nothing. (eg. CPU 3, HUMAN 4, - calculator gets 7 points, you get 0). Enter zero for the scores. Note that the calculator chooses its number before you but doesn't tell you it - it would be very easy for it to cheat, but read the program if you don't trust me. It is also very easy for the human to cheat using the memories that the calculator uses. "UNDERCUT" 3 -> L 3 -> K 0 -> G~I "RESET TACTICS (0~1)" ;0 for no, 1 for yes ? -> @ ;@ denotes theta @<>1 => Goto 9 .2 -> R:.4 -> S:.2 -> T:.2 -> U .3 -> V:.2 -> W:.2 -> X:.3 -> Y Lbl 9 Int (Ran*5+1) -> K ;first choice is always random 0 -> F Lbl 0 "NUMBER"? -> J J<1 => Goto 2 J>5 => Goto 2 ;anything strange then show scores J<>Int J => Goto 2 "CPU":K_ G+1 -> G Abs (J-K)=1 => Goto 1 ;if someone has undercut then goto 1 0 -> D J+H -> H:K+I ->I F=0 => Goto 3 F<5 => 1 -> E F>4 => 5 -> E 0 -> r .01/3*(J-K) -> Z ;frac not divide (I don't think it Z=0 => Goto 3 matters) -3Z+Q[F]<=0 => Goto 3 Lbl 7 Q[E]+Z>0 => r+1 -> r Q[E]+Z>0 => Z + Q[E] -> Q[E] E+1 -> E F<5 => E<5 => Goto 7 F>4 => E<9 => Goto 7 r*-Z+Q[F] -> Q[F] Goto 3 Lbl 1 J=K-1 => H+J+K ->H J=K-1 => -J-K -> D ;I wish this calculator had 'AND' or K=J-1 => I+J+K -> I 'OR' functions K=J-1 => J+K -> D F=0 => Goto 3 F<5 => 1 -> E F>4 => 5 -> E 0 -> r .01/3*-D -> Z -3Z+Q[F]<=0 => Goto 3 ;what is the point of the small '-' ??? Lbl 8 Z+Q[E]>0 => r+1 -> r ;and they put it over 'Ans' ???? Z+Q[E]>0 => Z+Q[E] -> Q[E] E+1 -> E F<5 => E<5 => Goto 8 F>4 => E<9 => Goto 8 r*-Z+Q[F] -> Q[F] Lbl 3 Ran -> @ L>= 4 => Goto 5 @<=V => 5 -> F @<=V+W => @>V => 6 -> F @<=V+W+X => @>V+W => 7 -> F @>V+W+X => 8 -> F Ran<.1 => Int Ran*4+5 -> F ;1/10 chance - choose a random tactic. F=5 => (Int Ran*2+4) -> K ;tactics 5 to 8 for if last human number F=6 => K-2 -> K ;was <= 3 F=7 => L-1 -> K F=8 => D<0 => Goto 3 F=8 => K<3 => -1 -> K Goto 6 Lbl 5 @<=R => 1 -> F @<=R+S => @>R => 2 -> F @<=R+S+T => @>R+S => 3 -> F @>R+S+T => 4 -> F Ran<.1 => Int Ran*4+1 -> F ;1/10 chance - choose a random tactic F=1 => K-2 -> K ;tactics 1 to 4 for if last human number F=2 => L-1 -> K ;was >= 4 F=3 => L-3 -> K F=4 => D<0 => Goto 3 F=4 => K<3 => -1 -> K Lbl 6 K<1 => Int (Ran*3+3) -> K K<1 => 0 -> F Goto 0 Lbl 2 "TURN":G_ "HUMAN":H_ "CPU":I_ Goto 0 The program works by assigning a probability to each tactic from two sets of four tactics. It then uses those tactics against the human player, lowering probabilities of certain tactics if they lose to the human, and vice versa - effectively learning. (Try putting in 5 continuously - pretty soon it chooses 4 all the time!) Obviously, it always follows your tactics changes so you have the advantage if you keep varying tactics (alternating between 3 and 5 sometimes gives it a headache) but it's not bad, and altering the tactics given could improve it. You need to play about 100 turns to be able to say that you can beat it - preferably 250! I read somewhere that you can use game theory to completely work the game out, and make a program that never loses as it randomly chooses the numbers in the optimum ratios, but I wanted to write a program that tried to outwit the human. A possible way to alter the game would be to give double (or triple, or squared etc.) points if you choose the same number twice or three times in a row. I might implement this at a later date. The only problem with this program is that as the only output is a single number between 1 and 5, and they're not deterministic, there might be a bug in the negative feedback loop and you would never know if it wasn't messing up. It would just play worse - and you don't even know how well it plays without any bugs! (eg. I recently found that one of it's tactics never did anything - just resorted to the catch-all random number - I'd never have noticed just by playing the game). Type it in carefully! _________________________________________________________________________