How to win at Rock-Paper-Scissors? (implementation of the optimal strategy in Wolfram Mathematica). How to always win the game of rock, paper, scissors

Translated from a post by Jon Mcloone, director of international business and strategic development at Wolfram Research. Original post: How to Win at Rock-Paper-Scissors
Download post as a Mathematica document

From a mathematical point of view, the rock-paper-scissors game (see appendix 1 at the end) is not particularly interesting. The Nash equilibrium strategy is very simple: randomly and equally likely to choose from three options, and given a large number of games, neither you nor your opponent can win. Although, when calculating the strategy with the help of a computer, it is still possible to beat a person after a large number of games.

My nine year old daughter showed me a program she created with Scratch that won absolutely every time just by keeping track of which choice you made before making your own! But I will introduce you to a simple solution that beats a person in rock-paper-scissors without cheating.

Since someone who always makes a completely random choice cannot be defeated, we will rely on the fact that people are not very random. If the computer can spot the pattern you are following in your attempts to be random, it will be one step closer to predicting your future actions.

I was thinking about creating an algorithm as one of the topics of our statistics course within the concept of Computer-Based Math. But the very first article I stumbled upon while looking for predictive algorithms considered the solution using a complex structure based on copula distributions. This solution was difficult for a student to understand (and maybe even for me), so I decided to develop a simpler solution that I could explain in simple terms. And even though it has already been developed before, it is much more fun to create things in your own way than to find them ready-made implementation.

To get started, we just need to be able to start the game. At that time, a demo was already developed and available that allows you to play rock-paper-scissors, but it was not quite what I needed, so I wrote my own version. This point does not require much explanation:

For the most part, this code describes the user interface and the rules of the game. The entire strategy of the computer player is contained in this function:

Where 1 corresponds to stone, 2 to paper and 3 to scissors. This is the optimal solution. No matter how you play, you will win as many games as the computer, and your win rate will hover around zero.

So now it would be interesting to rewrite the function choose Go to make a prediction about your choice using the recent games data stored in the variable history. The first step is to analyze the choices made during the last few games and find all occurrences of any sequence. By observing what a person did in each subsequent game, we can detect a certain pattern of behavior.

The first argument to the function is the history of past games. For example, in the data set below, the computer (second column, the second element of each sublist) has just played paper (corresponding to the number 2) against a human-played stone (number 1). This can be seen from the last element of the list. It can also be seen that this situation has already occurred twice, and both times the next move of the person was again a stone.

The second argument is the number of recent history elements to search for. In this case, the number 1 is passed as an argument to the function, which searches the data for only occurrences of (1,2). If we choose 2, then the function will look for occurrences of the sequence (3,2), (1,2) and return an empty list, since such a sequence has not been encountered before.

third argument, All, indicates that both human moves and computer moves must match in the desired sequences. The argument can be changed to 1 to look only at the human's move history (i.e. assuming that the human choice depends only on their previous moves), or 2 to only look at the second column, i.e. the computer's move history (i.e. assuming that the person responds to the previous moves of the computer, regardless of what moves he himself made and, therefore, regardless of whether he won or lost).

For example, in this case, we find that the person chose after the stone, regardless of what the computer chose in the same games.

With a large amount of data, we can only get by with the argument All, and the program will be able to decide for itself whose moves, computer or human, are more important. For example, if a computer's move history is ignored by a human in the course of making a choice, then the data set obtained for any computer move history will have the same distribution as for any other computer move history, provided there is enough data from previous games. By searching through all pairs of games, we get the same result as if we first selected data on the computer's move history, and then used this subset for the function shown above. The same will happen if only the history of the computer's moves matters. However, searching under both of these assumptions separately can yield better history matches, and this is most evident when the game dataset is small at first.

So from these two checks, we can find that the first gives a score of 100% that the person's next choice will be a stone, and the second shows that with a 75% probability the person will choose a stone and with a 25% probability - scissors.

And here I am somewhat stalled in solving the problem.

In this case, the two predictions are at least more or less close in results, although they diverge in the numerical values ​​of the probabilities. But if you're looking at three "slices" of data with a number of different history lengths, and the results of the predictions are inconsistent - how do you combine them?

I put a note about this problem in my "Blog it" folder and forgot about it until a few weeks ago there was an argument about how to cover the concept of "statistical significance" in a Computer-Based Math course.

I realized that the question is not how to combine the resulting predictions, but how to determine which of the predictions is the most significant. One of the predictions might be more significant than the others because it reflects a stronger trend or maybe based on a larger dataset. It didn't matter to me, so I just used the p-value of the significance test (with the null hypothesis that both players were playing randomly) to order the predictions.

I think I should listen to our own first principle that the first step in solving any mathematical problem is "the right question."

Now, if we take the last result we got, it turns out that the best prediction is a stone that has a p-value of 0.17. This means that with only a probability of 0.17, the data used for this prediction deviate from a discrete uniform distribution ( DiscreteUniformDistribution[(1,3)]), more by chance than by any systematic error, human or otherwise, that could change the distribution.

The smaller this p-value, the more confident we can be that we have found the true pattern of behavior. So we just make predictions for different history lengths and data slices and choose the prediction with the smallest p-value.

And we make a choice that will beat the choice of a person.

Here you see the result. You can download and try it out for yourself from the Wolfram Demonstrations website.

When the program has too little data, it plays randomly, so you start off equally. At first, when she first starts learning, she makes some stupid decisions, so you can get ahead. But after 30-40 games, she starts to get really meaningful predictions and you will see your win rate drop into the negative area and stay there.

Of course, such a solution is only good against primitive attempts to appear random. His predictability makes him prone to losing against a well-calculated and planned strategy. It is extremely interesting to try to defeat this program with the help of intuition. It is possible, but if you stop thinking or think too hard, you will soon fall behind. Of course, a program could easily do this by applying the same algorithm to predict the next move of that program.

This approach leads to the beginning of some kind of "arms race", a competition to write algorithms that will beat the opponent's algorithm in rock-paper-scissors, and the only way to stop this is to return to the Nash equilibrium strategy, choosing through RandomInteger[(1,3)].

Addition 1
In case you don't know how to play this game, the rules are as follows: you choose rock, scissors or paper using one of three gestures shown simultaneously by you and your opponent. Rock beats scissors (makes them blunt), scissors beats paper (they cut it), and paper beats rock (it wraps it up). The winner gets one point, in case of a draw both players get no points.

Thank you for your help in translating this post.

There is no person who has not played the game of Rock, Paper, Scissors. After all, she can not only take time, but also solve, for example, a dispute.

Meanwhile, not many people know that this game originated in China, later, in the 19th and 20th centuries, it gained popularity in many countries of the world, including Russia. And at the beginning of the 21st century, the first championships in this “sport” with significant prize funds appeared.

To win this game you do not need to be a psychic - to read the opponent's thoughts or program his actions, you just need to follow some rules.

1. Men tend to be the first to throw the “stone” because it is perceived as strength and determination. Therefore, it is possible to catch the strong half of humanity on this, they quite often come across on this. Using this feature, you can easily win by showing "paper". But remember that this trick will not work with experienced players.

2. If you are "lucky" to play with an experienced player, he is unlikely to show the "stone" for the first time - this is too obvious. Therefore, "scissors" is a fairly optimal option.

3. Tell your opponent what you are going to show and then...show what you said. Why? As long as you're not playing with someone who doesn't know you're being impudent, you can announce your intentions and get a profitable roll. For example, if you declare "rock", then your opponent will not throw out "paper", believing that you will show "scissors". This move can bring you a win or a draw.

4. If your opponent has thrown "scissors" twice, then the chance that he will show them a third time is very small. Most likely, he will throw out "paper" or "stone". In this case, it would be advisable for you to show "paper".

5. During the second round, inexperienced players subconsciously show what could defeat them in the past. For example, if your opponent was losing with "paper", he will show "scissors", then your move is "rock". If for the first time the opponent threw out the "stone", then the second time it is advisable to show "scissors": he will most likely decide to throw out the "paper".

6. There are situations when you do not know what to throw out. In this case, I advise you to show the "paper". According to statistics, "scissors" show a little less often than anything else. However, not so long ago, British scientists found that the most winning strategy in the game is to show “scissors”. The fact is that most often the opponent subconsciously expects the “stone” gesture, and therefore shows “paper”.

Good game!


God only knows how many controversial situations in childhood were resolved with the help of playing Rock, Paper, Scissors. Why are there little ones, full of adult kids who find an easy way out in a matter of seconds and a discarded sign. So what lies behind the unpretentious throwing out of fingers: a will of chance or a well-thought-out strategy? Scientists firmly know the answer and give their victorious recipe.

Just recently, a team of Chinese researchers from Zhejiang University announced the bold findings of their psychological tests to the world. Scientists from December 2010 to March of the current conducted 5 experimental cycles. Each cycle included 12 sessions with 6 participants. In total, the total number of subjects reached 360 people. The sex ratio was 217:143 with a female predominance (simply girls were more active in recording). A student or graduate student could participate in the study only once.

People were out of sight of each other, in front of the monitor screens. Thus, verbal and visual contact was excluded. Each of the participants spent from one and a half to two hours on 300 games with a random opponent. The incentive to win was a small cash reward for each round won. And here are the conclusions from this...

So what do you need to know to win? After observing a huge number of “battles”, the scientists found that the player who defeated his opponent in the current game was more likely to repeat his actions in the next round, and less likely to change anything.

On the other hand, if a player loses two or more times in a row, he will stop showing an unsuccessful combination and will try to break exactly the sign that just allowed his opponent to defeat him.

Thus, if player A was on a losing streak and player B had just rolled the scissors and thereby cut A's paper, then A would likely roll a stone, which would give a good chance of winning, since B would probably stick to the same winning tactics. The psychology of behavior is simple: if you win, you don't change, if you lose, you switch.

Lost? Roll the sign that beats your opponent's last winning sign.

Won? Don't keep showing the same sign, instead fold your losing opponent's last combo.

Still not completely clear? Here are some winning strategies that will help you stay invincible:

If you won the last game...

If you lost in the last game (and the opponent is not aware of this technique) ...

  • ... after throwing a stone, go to the scissors in the next fight
  • ... after throwing out the scissors, go to the paper in the next fight
  • ... after throwing away the paper, go to the stone in the next fight

If you lost the last game (and your opponent is aware of this technique)...

  • ... after throwing out a stone, go to paper in the next fight
  • ... throwing out the scissors, go to the stone in the next fight
  • ... after throwing away the paper, go to the scissors in the next fight

You can learn more about the methodology for conducting research in, provided by Chinese scientists to the public. Of course, it is designed in English and contains layouts and formulas that are incomprehensible to people far from mathematics.

And in conclusion, I’ll add that the blame for the lost cars, houses and wives in “stone, scissors, paper”, first of all, should be placed on your passion, and not on the Chinese minds and the author of these lines.

"Rock, paper, scissors" is a game familiar to everyone since childhood, it solved even the most serious male disputes. I always thought that this game is based on luck, but this is far from the case. Today "So simple!" will reveal to you a few little secrets that will allow you to always win in this game. And then you will ride in the front seat, and someone else will run for a beer.

The secret to winning Rock, Paper, Scissors

If you have already forgotten the rules, let me remind you: the stone breaks the scissors that cut the paper, and the paper covers the stone.

A team of Chinese researchers from Zhejiang University conducted a huge number of experiments and observations, the results of which showed some patterns: The player who defeated his opponent in the current game is most likely to repeat his actions in the next round and is unlikely to change anything.

On the other hand, if a player loses two or more times in a row, he will stop showing bad combination and will try to break exactly the sign that just allowed the opponent to defeat him.

Based on this, we can derive such a winning strategy

  • If you lose, roll the sign that beats your opponent's last winning sign.
  • If you win, don't keep showing the same sign, instead fold your losing opponent's last combo.

A few more important rules

  • Most often, the representatives of the stronger sex are the first to use a stone, so if your opponent is a man, try throwing paper.
  • If you are competing with an experienced player, there is a high chance that he will try to play on your naivety and throw paper. Use scissors.
  • Remember that if your opponent has already thrown a stone twice in a row, this person hates to be predictable and uses scissors most of the time. Throw a stone.
  • Watch your opponent's fingers. The lightest moves will tell you which move your opponent is going to use. All fingers are tense - a stone. All fingers are relaxed - paper. Only two fingers are tense - scissors.
  • Paper is used the least in the game - in 29.6% of cases. They use scissors more often - 35%. And even more often a stone - 35.4%. Use the effect of surprise.

Tell about these little tricks to yours, he will be absolutely delighted that he will always win arguments with his classmates!


We tend to think that the good old Rock, Paper, Scissors game is built on pure luck (or chance). But if it was, playit wouldn't be that interesting.

Corruption.Sport with a link to Bright Side reveals a few secrets for you, using which you can always win in this battle. And then you will ride in the front seat, and someone else will run for a beer.

First, let's start with the basics. As you probably know, conditionally, the stone breaks the scissors that cut the paper, and the paper covers the stone.

After observing a huge number of such "battles", a team of Chinese researchers from Zhejiang University found that the player who defeated his opponent in the current game, more likely to repeat their actions in the next round and less likely to change.

On the other hand, if a player loses two or more times in a row, it will stop showing bad combination and will try to break exactly the sign that just allowed the opponent to defeat him.

Based on this, a winning strategy :

  • Lost? Roll the sign that beats your opponent's last winning sign.
  • Won? Don't keep showing the same sign, instead fold your losing opponent's last combo.

And a few more tips:

  • Men are often the first to throw the stone. If you play against a man, try paper.
  • Experienced players will try to play on your naivety and throw paper. Use scissors.
  • When you see that an opponent has already thrown a stone twice, know that the person hates to be predictable and uses scissors most of the time. Use stone.
  • Watch your opponent's fingers. The lightest moves will tell you which move your opponent is going to use. All fingers tense - a stone. All fingers are relaxed - paper. Only two fingers are tense - scissors.
  • Paper is used the least in the game - in 29.6% of cases. They use scissors more often — 35%. And a little more often a stone - 35.4%. Use the surprise effect.