Close
0%
0%

How to be a Rock Paper Scissors Champ

An illustration of Bayes Theorem inspired by the book "The Signal and the Noise" by Nate Silver

samSam
Public Chat
Similar projects worth following
113 views
0 followers
Rock Paper Scissors is a seemingly random game...for humans. While the odds of a player winning any given game are just 1/3, not many people consider their opponents past history of choices when deciding on a winning strategy. This project demonstrates the ability of Bayes Theorem to give you the best chance of increasing your win percentage above the expected 33%. It will also show what strategies are best toward combating Bayes Theorem and give you the opportunity to interact with different strategies, view performance over the long run, and even analyze certain strategies' success or failure over multiple tests.

If you haven't read "The Signal and the Noise" by Nate Silver, I would highly suggest doing so. In Chapter 11 of his book entitled "If You Can't Beat 'Em...", he discusses the futility of beating the stock market in the long run. To emphasize his point, he mentions that strategies to beat the stock market in the long run "resemble a high-stakes game of rock-paper-scissors at best." Reading this reminded me of an old probability class I took because the Professor hosted a link to a Roshambo bot. The Professor challenged any student to beat the bot in the long run, but the best outcome you could expect was a draw - a third of the games were wins, a third were ties, and the bot was victorious for the last third. This expectation is exactly why Silver compared this children's game to beating the stock market in the long run, but what are the mechanisms at play that give the bot an advantage? 

Intro

This project hopes to shine some light on these mechanisms in a thorough manner. I decided to reproduce my Professor's bot but add more features to let you peek under the mathematical hood. Here is how you can learn more:

  • Go to my GitHub page, clone the repo, and start play against some of the bots. Which ones are easier/harder to beat?
  • Try facing the bots off against one another. Which are stronger/weaker? 
  • Come up with a couple of sequences and test them against every bot. Which bot performs best against your sequence? 
  • Take the results files from all of your tests above and make sure that you don't mistake the noise (a single game in which a weak bot is victorious over a strong one) for the signal (you can't beat the strongest bot in the long run).
  • Read on to learn more about Bayes Theorem and the math at play in this program


Bayes Theorem

A good introduction to this section regardless of how familiar you are with Bayes Theorem is to watch 3Blue1Brown's video and Veritasium's video. Both do an excellent job of reining in the math to tangible examples. Here is the formula restated:

But what is the evidence (E) and hypothesis (H) in the context of rock paper scissors? Let's consider a game in which the first round you lost to your opponent. The opponent chose rock (R) and you chose scissors (S). These facts are your evidence. You know in game 1, you chose S and your opponent chose R. Bayes Theorem will attempt to answer: "given the evidence, what is my opponent likely to pick next?" You will be able to calculate three probabilities: the probability that they will pick R, paper (P), or S, denoted P(r | e), P(p | e), P(s | e) respectively. Depending on whether you've played your opponent before or how confident you are in their play style, you can start the game with different likelihoods (P(E | H)) and priors (P(H)). For instance, the likelihood P(p | r) signifies how many times your opponent chose paper after choosing rock divided by the total number of times they chose rock. The prior P(s) is the total number of times your opponent picked scissors divided by the total number of games you have observed them play. We can then use these probabilities to inform ourselves about what choice is most likely to result in a win. Then, using the evidence from game 2, we refine our likelihood and prior estimates, then recalculate the probabilities of our opponent picking R, P, or S given the new evidence.

Your likelihood models can be as thorough as you like. You can build a model that only considers one step into the past, multiple steps into the past, or even a model that also considers the outcome of the game or the choices you made in estimating the probability of R, P, or S. The following example will just consider the case of one step into the past. 


  • 1
    Clone the repository

    Go to my GitHub page and clone the RockPaperScissors repository.

  • 2
    Follow the instructions on the README to build, compile, and execute the program

    I recommend doing this in a desktop Linux environment. I have not tested this procedure on either Windows or Mac.

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates