Rock-Paper-Scissors: You vs. the Computer
nytimes.com
nytimes.com
perl -e "@a = qw/rock paper scissors/;print $a[int rand 3];"
34 wins, 31 ties, 35 losses
I had assumed there would be more bias in it if it were trying to exploit human patterns and that choosing randomly like this would in turn allow me to exploit it as it looked for nonexistent patterns in my choices.
Apparently there wasn't that much bias to take advantage of or it learned that I was choosing randomly and compensated by doing the same. Or maybe I just didn't choose a large enough sample and got unlucky, I'm not too sure. I will say that I was winning a lot more during the first half, though.
But maybe I committed a statistical fallacy somewhere in that line of reasoning, because it sure didn't win.
Imagine the other tries to exploit your imagined human non-randomness and plays rock all the time. You play totally random, so on the long term you win/lose/tie roughly same number of times.
You would be taking advantage if you played paper all the time.
You're right. I was just thinking that 1/3, 1/3, 1/3 was the Nash equilibrium and not really thinking the whole thing through. Once I gave it a little more thought, I came up with the same rock example you gave.
It seems to use a history depth of 5, both for you and it. So it creates a 'fingerprint' from your past 5 moves and it's past five moves, and then picks what is the most winning move in it's history given that same fingerprint.
That strategy seems to work reasonably well, I tried to just go all paper for a while and it responded with all scissors. Ouch.
Seems like it would act exactly as you've just described no?
Edit: Ok re-reading your initial post I think I misunderstood you. However it still doesn't explain how it could pick up the pattern quick enough - there are 3 possible responses each time, so until it's tried all 3 responses it won't know which is best given the fingerprint. However it will pick up the pattern by the 2nd cycle.
I think it's using a more sophisticated learning strategy than you suggest.
But once it builds up a database, I imagine that is far more effective.
Over 20 games I end up tied in wins/loses with the untrained version plus greater than half straight ties. It seemed I should be able to add one more layer of "predict" to my crazy rock-paper-scissors reasoning and win solidly but it didn't seem to change the results at all. I wonder if it just progressed evenly with me.
On the other hand, I firmly beat the trained version with 80-90% win and mostly ties making up the remainder.
I'd be interested to see the algorithm behind it as I get the feeling the untrained version was making good choices for all the wrong reasons and with a slightly more complex game it would show.
Even though it appears to be that you both have an equal chance to win (both of you have 33%), why would someone offer you an equal game unless he had some sort of advantage that you aren't aware of?
The trick was to look at the opponents hand while it was still going down. If you're throwing rock or scissors, your hand will be clenched the whole way down. If you were throwing paper, you will probably open your hand halfway down your throw.
So when he sees you opening your hand, midway he will change his to scissors. And if it doesn't stay open, then he will use rock, since between rock and scissors, rock will either win or tie. It required a bit of hand dexterity, but he practiced wing-chun, so it wouldn't have been a problem for him. Of course, the trick doesn't work 100% of the time, so you were allowed a maximum of two tries discounting ties, preventing kids from getting winning streaks.
It was a pretty interesting lesson, and I was glad that I skipped my statistics class to go to his.
http://leftoversoup.com/archive.php?num=34
and you can play the game online at an older site, here: http://tailsteak.com/archive.php?num=198
Unfortunately, he doesn't seem to have come up with a computer player engine that I've seen, so you're stuck playing against yourself. Maybe if someone's looking for a challenge... ;)
Now that I think of it, this guy should get more attention here. The creator of webcomic 1/0 (http://www.undefined.net/1/0/) is a man of many interesting ideas in a variety of fields, well worth a moment of the young entrepreneur's time.
Go check him out!
[EDIT: Before anyone asks, NO! He is NOT me!]
Nice little program.
+SCISSORS =PAPER +PAPER +ROCK =SCISSORS =ROCK +SCISSORS +PAPER -SCISSORS =SCISSORS =PAPER +PAPER +PAPER -ROCK +ROCK +SCISSORS +SCISSORS
win @ repeat: 5, win @ change: 5, loss @ repeat: 0, loss @ change: 2, draw @ repeat: 1, draw @ change: 4
First 5 throws are 100% predictable and its results are used by the program for subsequent predictions. It's too easy to set up traps.