I noticed that there isn’t too much discussion on the Rock Paper Scissors project (in Machine Learning with Python), which is a shame! Having completed nearly every fCC project, this is definitely one of my favorites.

So for those that don’t know/remember: the project involves creating an algorithm to play Rock-Paper-Scissors against other algorithms (bots). The challenge is to create an algorithm that can consistently achieve a 60% win rate (or better) against 4 other bots. Three of the bots aren’t too tough. My final algorithm wins 96% agains Kris, 84% agains Mrugesh, and 99% against Quincey. But *Abbey* is real trouble - my final algorithm still only barely scrapes by with a 60.5% win rate.

What I learned is that Abbey uses a Markov Chain to predict your bot’s next move, and apparently the best way to beat Abbey is to match it with another (longer) Markov Chain.

So my final solution starts with a Markov Chain that looks for patterns with a length of 3. If it doesn’t find one, the next part of the algorithm looks for a patterns with a length of 2. If it’s still not found, the algorithm then looks for the *least* used move and picks a counter that is likely to match or tie the bot (so if the least used move is “R”, my bot will pick “S” since the opposing bot is likely to either pick “S” or “P” - hopefully that makes sense).

But even with all this, I still wasn’t beating Abbey over 60% of the time. What pushed my algorithm over the edge was learning that it might be a good idea to limit the Markov Chain’s memory. So, for example, instead of looking at *all* prior plays from the opposing bot, only look at the most recent 100. I played around with this and - for some reason - looking at only the previous 22 moves seemed to be ideal. Not 21, not 23, but it has to be 22. Why? I have no idea… I really don’t understand it, but that seems to work.

Also, my opening move is always “S” - anything else, my win percentage against Abbey drops. This is a mystery to me.

Anyway, I just had so much fun playing with this project, I wanted to share! I’d love to hear what anyone else did to solve this one.