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

Translation of 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 the post as a Mathematica document

From a mathematical point of view, the game rock-paper-scissors (see Appendix 1 at the end) is not particularly interesting. The Nash equilibrium strategy is very simple: choose randomly and with equal probability from three options, and given a large number of games, neither you nor your opponent can win. Although, when calculating the strategy using 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 using Scratch that won absolutely every time simply by keeping track of what choices you made before making yours! But I will introduce you to a simple solution that beats a person in rock-paper-scissors without cheating.

Since it is impossible to defeat someone who always makes a completely random choice, we will count on the fact that people are not very random. If the computer can notice the pattern you follow 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 in our statistics course under the Computer-Based Math concept. But the first article I came across in my search for predictive algorithms examined the solution using a complex design based on copula distributions. This solution was difficult for a school student to understand (and perhaps even for me), so I decided to develop a simpler solution that I could explain in simple terms. And even if it has already been developed before, it is much more fun to create things your own way than to find a ready-made implementation of them.

To begin with, we just need to be able to start the game. At that time, a demo had already been developed and was available that allowed 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 rules of the game. The computer player's entire strategy is contained in this function:

Where 1 corresponds to rock, 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 chooseGo to make a prediction about your choice using the latest games data stored in the variable history. The first step is to analyze the choices made over 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 (the second column is the second element of each sublist) has just played a paper (the number 2) against a stone played by a human (the number 1). This can be seen from the last element of the list. It is also clear that this situation has already arisen twice, and both times the person's next move was again a stone.

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

Third argument All, indicates that in the required sequences both the human moves and the computer moves must coincide. The argument can be changed to 1 to look only at the history of the person's moves (that is, assuming that the human choice depends only on his own previous moves), or 2 to look only at the second column, that is, the history of the computer's moves (that is, assuming that a 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.

Given a large amount of data, we can only make do with an argument All, and the program will be able to decide for itself whose moves, the computer’s or the person’s, are more important. For example, if a computer's history of moves is ignored by a human when making a choice, then the data set obtained for some history of computer moves will have the same distribution as for any other history of computer moves, provided that there is enough data on previous games. By searching through all pairs of games, we get the same result as if we first selected data from the history of the computer's moves, and then used this subset for the function shown above. The same will happen if only the history of the computer's moves matters. But at the same time, by searching with both of these assumptions taken into account separately, you can get more accurate matches in history, and this is most evident in cases where the data set about games is small at first.

Thus, from these two tests, we can find that the first gives an estimate 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 stuck in solving the problem.

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

I filed a note about this issue in my "Write a blog about this" folder and forgot about it until a few weeks ago when 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 most significant. One of the predictions might be more significant than the others because it reflects a stronger trend or perhaps is based on a larger data set. This didn't matter to me, so I simply used the p-value of the significance test (with the null hypothesis that both players are playing by chance) to rank order the resulting predictions.

I think I should listen to our own first principle that the first step in solving any mathematical problem is “the correct formulation of the question.”

Now, if we take the last result we got, it turns out that the best prediction is stone, which has a p-value of 0.17. This means that there is only a probability of 0.17 that the data used for a given prediction deviates from the discrete uniform distribution ( DiscreteUniformDistribution[(1,3)]), and more by chance than due to systematic error, whether human or any other reason, which could change the distribution.

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

And we make a choice that will beat the person’s choice.

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

When a program has too little data, it plays randomly, so you start out on equal footing. At first, when she is just starting to learn, she makes some stupid decisions, so you can get ahead. But after 30-40 games it starts to get really meaningful predictions and you will see your win rate go into the negative area and stay there.

Of course, such a solution is only good against primitive attempts to appear random. Its predictability makes it susceptible to possible loss against a well-calculated and planned strategy. It is extremely interesting to try to defeat this program using intuition. It is possible, but if you stop thinking or think too hard, you will soon fall behind. Of course, the program could easily do this by using the same algorithm to predict the program's next move.

This approach leads to the beginning of a kind of “arms race”, a competition to write algorithms that will win rock-paper-scissors against the opponent’s algorithm, and the only way to stop this is to return to the Nash equilibrium strategy, making choices through RandomInteger[(1,3)].

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

Thank you for your help in translating this post.

God only knows how many controversial situations in childhood were resolved by playing “Rock, Paper, Scissors.” Why are there kids, there are a lot of grown-up kids who find an easy way out in a matter of seconds and a discarded sign. So what is hidden behind the simple throwing of fingers: chance or a proven strategy? Scientists firmly know the answer and give their winning recipe.

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

People were out of sight of each other, in front of monitor screens. This eliminated verbal and visual contact. Each participant spent from one and a half to two hours playing 300 games with a random opponent. The incentive to win was a small monetary 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", scientists found that a 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 the bad hand and try to break the very sign that just allowed his opponent to beat him.

Thus, if player A was on a losing streak, and player B had just thrown away the scissors, thereby cutting A's paper, then A would likely have thrown a stone, which would have a decent chance of winning, since B would likely stick the same winning tactics. The psychology of behavior is simple: if you win, you don’t change, if you lose, you switch.

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

Did you win? Don't keep showing the same sign, instead throw out your losing opponent's last hand.

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

If you won the last game...

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

  • ...after throwing away the stone, move on to scissors in the next fight
  • ...throwing out the scissors, move on to paper in the next fight
  • ...throwing away the paper, move on to the stone in the next fight

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

  • ...throw away the stone, go to the paper in the next fight
  • ...throwing away the scissors, move on to the stone in the next fight
  • ...throwing away the paper, move on to the scissors in the next fight

You can familiarize yourself in more detail with the research methodology provided by Chinese scientists to the public. Of course, it is written in English and contains layouts and formulas that are difficult to understand for people far from mathematics.

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

BENJAMIN JAMES DYSON, Lecturer in Psychology at the British University of Sussex, co-author of the study “The Impact of Negative Outcomes on Irrational Decision Making in the Game of Rock, Paper, Scissors”:

1 ___________

One day I saw two of my thesis students playing rock, paper, scissors in front of my office to see who would go first. One of them was confident of his victory, I asked why, we began to consider possible strategies and ended up writing a whole study together. We were curious to prove that decision-making in this game is influenced by emotions, and to demonstrate exactly how. We didn’t set out to learn how to always win, but along the way we found out what behavioral patterns contribute to this. For example, in the first round, most players unconsciously choose a stone. It's not even that it's associated with reliability, it's just that we start the game with this gesture when we shake our fist. Therefore, in the first game it is better to “throw away” the paper.

2 ___________

The average person does this: if an item is won, the euphoria of victory makes you bet on it again - we like to do things for which we receive a reward. And vice versa, if you bet on scissors and lose, in the next round you will most likely change tactics, choosing a stronger object - a stone. In fact, you need to watch what your opponent chooses. If he loses, repeat his item in the next round, and if he wins, bet on a stronger one.

3 ___________

Acting based on your opponent's behavior is a smart strategy, but what if the opponent understands what you are doing and is trying to adjust? Then the game becomes much more difficult. In this situation, there is only one way to protect yourself from losing - mix strategies randomly so that your actions are not predictable. Once you can even give in on purpose.

3 ___________

Our goal was not to teach people to cheat, but to force them to reconsider decisions dictated by emotions. Both failure and victory make us vulnerable in their own way. The mistake described in our study is often repeated by roulette players, unknowingly following the Martingale principle: having bet on black or red and winning, they stubbornly continue to bet only on the “lucky” color and quickly go broke. Professional poker players know that even when you lose, you can make a profit if you keep a cool head.

5 ___________

31 study participants played “Rock, Paper, Scissors” 6,975 times; the opponent was a computer program operating according to a mixed equilibrium strategy. Having played a “draw”, players begin to behave as if they had lost, because on a subconscious level, a “draw” is perceived as a defeat. The international Rock, Paper, Scissors championship, held on April 16 at the Green Man pub in London, was attended by players from 196 countries.

“Rock, paper, scissors” is a game familiar to everyone since childhood; it resolved even the most serious male disputes. I always thought this game was just based on luck, but that's far from the truth. Today "So simple!" will tell you a few little secrets that will allow you to always win this game. And then you will ride in the front seat, and someone else will run for 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: A player who defeats his opponent in the current game will most likely repeat his actions in the next round and is unlikely to change anything.

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

Based on this, we can derive the following winning strategy:

  • If you lose, throw out the sign that beats your opponent's last winning sign.
  • If you win, don't continue to show the same sign, instead throw out your losing opponent's last combination.

A few more important patterns

  • Most often, the stronger sex uses the stone first, 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 the paper. Use scissors.
  • Remember that if your opponent has already thrown the stone twice in a row, that person hates being predictable and will use scissors in most cases. Throw a stone.
  • Watch your opponent's fingers. The slightest movements will tell you what move your opponent is going to use. All fingers are tense - stone. All fingers are relaxed - paper. Only two fingers are tense - scissors.
  • Paper is used least often in the game - in 29.6% of cases. Scissors are used more often - 35%. And even more often stone - 35.4%. Use the effect of surprise.

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

Variations of the game “Rock, Paper, Scissors” were invented hundreds of years ago. But like most games, this one is more than just a fluke. This is a battle of patterns, psychology and statistics. Want to know what statistics, research and experts have to say about winning this game?

Psychology

According to the global community organization Rock, Paper, Scissors, the idea of ​​throwing away a “rock” is fatal to newbies. Men make this move especially often. It turns out that choosing this move has a lot to do with the idea that the “stone” is perceived as “strong” and “strong-willed,” which is why men tend to choose it. And since the enemy will guess that you will throw the “rock”, you must first choose “scissors”.

A word from the researchers

Researchers from Zhejiang University, specializing in game theory, looked at the patterns that people tend to choose to play. They recorded the game results of 360 students who played 20 thousand rounds of the game. As an incentive, students who won were paid money.

In all games, each option was chosen about the same number of times, as you would expect. However, the researchers noticed a clear pattern in the people's tactics. According to the scientists, people who won tended to take longer to choose an action. On the other hand, students who lost tended to alternate between choosing “rock,” then “scissors,” and then “paper.” If you want to win given this data, it will depend on whether your opponent knows about it. But if we assume that he doesn’t know about it, then we can say with confidence that he will choose the same action again if he just won against you thanks to it.

Mind games

Just like in a game of poker, you can easily defeat your opponent by using the Machiavellian power of suggestion. The age-old tactic of announcing which hand you'll be playing can be a useful trick. As long as you're not playing with someone who actually thinks you're brave enough to talk about your move and then actually make it, you can change the move to one that beats the one you previously announced . So, if you say you will throw "rock", your opponent will throw "paper". This means that “scissors” will give you a draw at worst, and a victory at best.

Finally, when the rest of the odds are gone, your safest bet may be paper, as statistically it's only chosen 29.6% of the time, not the 33.33% you'd expect.