Web Design. Development. Optimization. RSS 2.0
 Thursday, May 20, 2004

So one question comes to mind when thinking about my Rock Paper Scissors web service: is there any way I can improve the algorithm so I can win?

At first, it appears hopeless. If you take one “truly random” RPS player and pit him against another “truly random” RPS player, each player has a 50% chance of winning. Neither has any advantage, and so you are leaving the results of the game up to chance.

But what about non-random players? If you take an RPS player who always plays “Rock” and pit him against a “truly random” RPS player, each player still has a 50% chance of winning. The results of the game are also up to chance.

There should be a number of optimizations that I can add to my algorithm to recognize and defeat non-random players however. What if my opponent always plays “Rock”? I should be able to recognize that as a pattern and start playing “Paper”. In this situation, if I program it intelligently enough, I should be able to defeat any opponent who always plays the same move by a score of 20-2-3 over 25 games.

Thinking along the same lines, there are also other patterns besides the opponent who always plays the same move. What about opponents who cycle over the three moves in a predictable order? “Rock, Paper, Scissors, Rock, Paper, Scissors, Rock...” That's another pattern that can be looked for and effectively defeated.

Thinking about patterns, you can really go overboard, but why? So what if you test for a really complex pattern (like a Fibonacci series)? Noone is going to intentionally programm their RPS game to follow a Fibonacci series. Stick to the simple patterns - the ones lazy programmers are likely to use.

Finally, a word about odds and statistics. In any coin-flip scenario, the odds of each side of the coin are about even. If you flip a coin 1000 times, you will get heads about 500 times and tails about 500 times, plus or minus a relatively small range. That's odds.

Can you use this “even odds” to your advantage if you notice a player who's random RPS moves are a bit uneven? Can you “count cards” like a blackjack player? It's hard to tell. I'm going to do some more research and see if understanding the statistics of a game in progress can help you.

 

Thursday, May 20, 2004 9:24:05 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
.NET
Del.icio.us Digg Technorati Blinklist Furl reddit
Comments are closed.
Archive
<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Scott Duffy
Sign In
Statistics
Total Posts: 470
This Year: 30
This Month: 0
This Week: 0
Comments: 73
Themes
Pick a theme:
All Content © 2008, Scott Duffy
DasBlog theme 'Business' created by Christoph De Baene (delarou)