You can’t beat this algorithm

IRMA (Invisible Rock-Paper-Scissors Medium Algorithm) is a fortune teller that can predict with an accuracy of ~70% your next move at rock-paper-scissors game.

Timothée Simon
Software Engineer
Published
April 16, 2021

At my company (Hackages) we organise HackFridays. Every other Friday, we get one full day to experiment with tech we want to discover or learn more about. For me, the choice was deep learning. But as a frontend dev I discovered it is quite hard to implement in the frontend. And this is how IRMA was born.

IRMA

IRMA (Invisible Rock-Paper-Scissors Medium Algorithm) is a fortune teller that can predict with an accuracy of ~70% your next move at rock-paper-scissors game. You can try it here, but be careful of the spell that could be cast on you if you beat her…
You can also use the j-k-l buttons on your keyboard to play faster.

The technical side

IRMA is just a statistical computing algorithm that learns from the player. It remembers every move and tries to predict the next one based on the previous successions. If you think you can be smarter than IRMA and generate random moves, try to stay below 50% accuracy after 100 moves.
Human beings are not able to deliver true randomness, and IRMA knows it!

Let’s take for example the 20 first moves an user (me) made:

["📝", "✂️", "✂️", "🗿", "✂️", "📝", "🗿", "📝", "🗿", "🗿", "✂️", "🗿", "📝", "✂️", "📝", "🗿", "✂️", "📝", "🗿", "✂️"]

It looks pretty random and it seems like it would be really difficult to predict my next move.
Now let’s try to divide this list in 3-grams. The 3-grams is the list of all successions of 3 choices that were made by the user.
This is not the same as dividing the list by groups of 3, for example the list [a, b, c, d] would produce 2 grams: [a, b, c]and [b, c, d].

Here we have:

["📝", "✂️", "✂️"]
["✂️", "✂️", "🗿"]
["✂️", "🗿", "✂️"]
["🗿", "✂️", "📝"]
["✂️", "📝", "🗿"]
["📝", "🗿", "📝"]
["🗿", "📝", "🗿"]
["📝", "🗿", "🗿"]
["🗿", "🗿", "✂️"]
["🗿", "✂️", "🗿"]
["✂️", "🗿", "📝"]
["🗿", "📝", "✂️"]
["📝", "✂️", "📝"]
["✂️", "📝", "🗿"]
["📝", "🗿", "✂️"]
["🗿", "✂️", "📝"]
["✂️", "📝", "🗿"]
["📝", "🗿", "✂️"]

Still looks pretty random, but maybe you can already spot some patterns. This is because, even for only 20 values I struggled to create random data, fearing to repeat myself, and yet I still did without realising it.

Now let’s take the last 2 values : ["🗿", "✂️"] and filter out all the grams that do not start with those values:

["🗿", "✂️", "📝"]
["🗿", "✂️", "🗿"]
["🗿", "✂️", "📝"]

As we can see, I have the tendency to put a "📝" after writing ["🗿", "✂️"], so IRMA will play "✂️". If you do this with a lot of data and several grams sizes , you will have a fully functioning IRMA.

Conclusion

IRMA is not deep learning, but can still be considered machine learning. Unlike deep learning, it does not require a lot of computing power. To prove this, IRMA runs solely in the frontend with Javascript.
It can be a good alternative for developers who want to implement a bit of “magical” intelligence to their frontend easily without extreme statistical knowledge and without some of the disadvantages of deep learning.

If you have idea to improve IRMA or idea of real world adaptation don’t hesitate to leave a comment ;)

Want to have a look at how HackFriday looks like? Have a look at our video!

Hackages is an educational platform with the mission of improving developers and businesses' skills and helping them acquire new ones.
Home
Tutorials
Blog
Webinars