Game theory in The Matrix – the mathematics of dueling

One of my favorite scenes in The Matrix is the subway fight scene (clip below).

Rather than run away, Neo chooses to fight Agent Smith head on. The scene begins with a duel which I find particularly interesting due to the strategies they take.

Here is a link to the video. The duel that I am going to discuss is roughly the first 30 seconds of the video.

Youtube video: The Matrix subway fight

The detail I find most interesting is the order in which the two shoot their bullets.

It appears that Neo takes the first shot, but then they mostly fire at almost the same time. This becomes clearer as Neo and Agent Smith run towards each other. When they jump in the air and approach point blank range, the clip moves into super slow motion and it is clear they fire their bullets at exactly the same time.

In the film the simultaneous firing has the beauty of symmetry and the timing was probably chosen for aesthetics.

But one can ask: does it make sense that Neo and Agent Smith fire at the same time?

At this point in the film, Agent Smith appears to be more skilled than Neo. If we were thinking about the strategy of a duel, should the more accurate shooter fire first, or should he wait?

What’s the right time to shoot in a duel?

A simple dueling game

Consider a duel between two players A and B.

For simplicity, suppose each only has one bullet. The game works as follows.

A and B start the duel at a distance t = 1 from each other. They approach each other at the same speed, and each has to decide when to shoot.

As they get closer to each other, their accuracy increases. At distance t, the player A has a chance a(t) of killing his opponent, and for player B it is b(t). Assume both players are aware of the other’s skill.

In this duel, missing your shot is very costly. If a player shoots and misses, then the other player keeps approaching until he gets to point blank range and shoots with complete accuracy.

What is the optimal strategy of this game? That is, at what point should each player shoot?

Solution: when player A should fire

The tricky part to the game is balancing when to shoot. If you fire too early, then your opponent kills you for sure. If you wait too long, then you can also get beaten if your opponent is a good shot.

We can think about when player A should fire by listing out the chance of surviving in the different possibilities of firing at point t.

  • If player A fires first: Player A will survive only if he hits, which happens with chance a(t)
  • If player A waits to fire: Player A survives only if player B misses, which happens with chance 1 – b(t)

Now we can reason out player A‘s strategy. Player A will want to fire first if his chance of hitting is greater than player B‘s chance of missing:

a(t) ≥ 1 – b(t)

But he must also be careful not to fire too early. He should always wait if his chance of hitting is smaller than player B’s chance of missing:

a(t) ≤  1 – b(t)

Putting those two equations together, we can see that Player A should shoot at the time when he is at distance t* where

a(t*) = 1 – b(t*)

Or alternately written,

a(t*) + b(t*) = 1

Solution: when player B should fire

We can do the same exercise for player B. Notice the same conditions are true:

  • If player B fires first: Player B will survive only if he hits, which happens with chance b(t)
  • If player B waits to fire: Player B survives only if player A misses, which happens with chance 1 – a(t)

Now we can reason out player B‘s strategy. Player B will fire first, if his chance of hitting is better than his opponent’s chance of missing:

b(t) ≥ 1 – a(t)

But he must also be sure not to fire too soon. He needs to wait so long as his chance of hitting is smaller than his opponent’s chance of missing:

b(t) ≤ 1 – a(t)

Putting those two equations together, we can see that Player B should shoot at the time when he is distance t* where

b(t*) = 1 – a(t*)

Or alternately written,

a(t*) + b(t*) = 1

Solution: they fire at the same time!

From the equations, you’ll notice that both players choose to fire at the same time! There is one specific distance which is optimal for both players.

This would not be surprising if the two players had the same accuracy level. But we solved this game using the assumption their accuracy levels were different.

So why do they end up shooting at the same time?

We can reason why this must be the case. If one person chose to fire earlier than another, say 5 seconds earlier, then he would be better off waiting. His opponent is not shooting for another 5 seconds, so he might as well wait a few more seconds to get closer and increase his accuracy.

As the equations show above, the right time to shoot is just when your chance of hitting equals your opponents chance of missing. And since one person’s failure is another person’s success, this means both players choose the same time when they are a distance such that their accuracy functions sum to a probability of 1.

The Matrix duel

While Neo does fire the first bullet, the two do appear to fire shots at almost or exactly the same time as they run towards each other.

But then again, it should come as no surprise that Neo and Agent Smith play smart strategies given their superhuman abilities.

Additional reference

The theory of duels is covered in much more detail in this game theory lecture at Yale.

Lecture 16 – Backward induction: reputation and duels

The relevant part about duels–he uses two players with wet sponges–starts about 25 minutes into the video.

Youtube video: Lecture 16 Game theory at 25 min 28 seconds



Share this post:

| More

Previous post:

Next post:



  • Asim

    Doesnt the game change completely when there are
    a) infinite bullets
    b) sufficient no of bullets to fire at an x interval of time such that the last bullet is fired at 0 distance
    c) more than 1 bullet
    .. any ideas?

  • Asim

    They would perhaps still fire at the same time; but it will go away from being a game of waiting for optimum distance to the ability to fire first

  • Scott

    I decided to try this from a different point of view, by constructing a payoff table for a given instance in time (t).

    I also adhered to the following rules/assumptions:

    1) Above all else, each player wishes to avoid getting shot (value -1).
    2) Secondarily, each player wishes to shoot the other player (value 1).
    3) If each player misses the other the duel is a draw (value 0). Likewise, if each player waits for a given period of time, the payoff for that time is 0.
    4) If one player misses, and the other has yet to fire, the other player wins by default (value -1).

    Now, I prioritized rules 1 and 2 that way because of the case where A and B both shoot and hit each other. To me it seemed that winning a duel is pointless if you die yourself.

    The most complicated scenario, then, is when both players decide to fire (A-fire, B-fire). This has four sub-components:

    A-fire,B-fire
    ————-
    A-fire-hit, B-fire-hit
    Probability: a(t)b(t)
    Value: -1

    A-fire-hit, B-fire-miss
    Probability: a(t)(1-b(t))
    Value: 1

    A-fire-miss, B-fire-hit
    Probability: (1-a(t))b(t)
    Value: -1

    A-fire-miss, B-fire-miss
    Probability: (1-a(t))(1-b(t))
    Value: 0

    The overall value for each sub-case is the probability*value; the overall value for the case, [A-fire, B-fire], is the sum of each sub-case’s values.

    -a(t)b(t) + a(t)(1-b(t)) – (1-a(t))b(t) + 0
    -a(t)b(t) + a(t) – a(t)b(t) – b(t) + a(t)b(t)

    Overall Value for A-fire, B-fire:
    a(t) – a(t)b(t) – b(t)

    Next:

    A-wait, B-fire
    ————–
    A-wait, B-fire-hit
    Probability: b(t)
    Value: -1

    A-wait, B-fire-miss
    Probability: (1-b(t)
    Value: 1

    Overall Value:
    -b(t) + (1-b(t))
    -b(t) + 1 – b(t)
    1 – 2b(t)

    Now, what’s interesting is that, in the case of B-fire, it is always better for A to wait because:

    [a(t) - a(t)b(t) - b(t)] is only greater than [1 - 2b(t)] when a(t) is greater than 1 (more than 100% probability). This makes sense given that, if B-fires his chance of hitting or missing is the same, regardless of what A does. If A gets hit, he loses no matter what he does so it boils down to a choice of firing as well, and potentially missing, resulting in a draw (if they both miss), or waiting and securing a sure win if B misses.

    Both cases converge to -1 for A as time goes on.

    Now, what if B waits?

    A-fire, B-wait
    ————–
    A-fire-hit, B-wait
    Probability: a(t)
    Value: 1

    A-fire-miss, B-wait
    Probability: (1-a(t))
    Value: -1

    Overall Value:
    a(t) – (1-a(t))
    a(t) – 1 + a(t)
    2a(t) – 1

    A-wait, B-wait:
    —————
    Value: 0

    This is an easier case to evaluate. If B waits, then A should fire when 2a(t) – 1 > 0, or when a(t) > 0.5 (50% probability).

    This allows us to break the time-line into two parts:
    When a(t) 50%.

    When a(t) 50%, the strategies for each case differ. If B fires, it’s better for A to keep waiting, if B waits, it’s better for A to fire. So how to choose?

    Since we presume that each knows the other’s skill level, then A can determine what b(t) is that time and determine whether or not b(t) is greater or less than 50%. If b(t) 50%, then B is in the same position as A. Again, how to choose if both a(t) and b(t) > 50%?

    First, we should note when it is possible for both a(t) and b(t) to be > 50%.

    If A and B are of different skill levels, each will cross the 50% line at different times. When both a(t) and b(t) are <= 50%, both will wait, whereas, the first person to cross the line will know that the other player will continue to wait and, thus, will fire himself, ending the duel.

    The only time both A and B will be at 50% is if they hit the line at the same time, being at the same skill level.

    If could reason that, being at the same skill level, they should each decide the same way. Either they both fire [a(t) - a(t)b(t) - b(t)] or both continue to wait [0]. Now, since in this scenario a(t) = b(t), we can reduce [a(t) - a(t)b(t) - b(t)] to -(a(t)^2) which can't ever be greater than 0, meaning each should wait. However, knowing that each should wait means that each should also fire since you should fire when the other waits and your probability is greater than 50%. At this point, I'm not sure how to resolve this dilemma.

    Summary:
    With two players of differing skills, each will wait when both of their probabilities of hitting are less than 50%. The first person to reach a hit probability of 50% will fire first.

  • Scott

    Sorry if my post seems a bit odd. I used greater than and less than symbols, which I think the website parsed incorrectly. I have reposted the latter half of the post here:

    This allows us to break the time-line into two parts:
    When a(t) is less than or equal to 50% and when a(t) is greater than 50%.

    When a(t) is less than or equal to 50%, it’s better for A to wait, regardless of what B does, given the reasons for both cases [B-fire, B-wait] above.

    When a(t) is greater than 50%, the strategies for each case differ. If B fires, it’s better for A to keep waiting, if B waits, it’s better for A to fire. So how to choose?

    Since we presume that each knows the other’s skill level, then A can determine what b(t) is that time and determine whether or not b(t) is greater or less than 50%. If b(t) 50%, then B is in the same position as A. Again, how to choose if both a(t) and b(t) are greater than 50%?

    First, we should note when it is possible for both a(t) and b(t) to be greater than 50%.

    If A and B are of different skill levels, each will cross the 50% line at different times. When both a(t) and b(t) are less than or equal to 50%, both will wait, whereas, the first person to cross the line will know that the other player will continue to wait and, thus, will fire himself, ending the duel.

    The only time both A and B will be at 50% is if they hit the line at the same time, being at the same skill level.

    If could reason that, being at the same skill level, they should each decide the same way. Either they both fire [a(t) - a(t)b(t) - b(t)] or both continue to wait [0]. Now, since in this scenario a(t) = b(t), we can reduce [a(t) - a(t)b(t) - b(t)] to -(a(t)^2) which can’t ever be greater than 0, meaning each should wait. However, knowing that each should wait means that each should also fire since you should fire when the other waits and your probability is greater than 50%. At this point, I’m not sure how to resolve this dilemma.

    Summary:
    With two players of differing skills, each will wait when both of their probabilities of hitting are less than 50%. The first person to reach a hit probability of 50% will fire first.

    Addendum:
    I also hadn’t considered when A and B are of different skill levels, but start the duel already both being above 50%.

  • Steve

    I just want to add a real-world answer to the discussion. The correct action in a gun dual at relatively short range with no cover available is:

    1) Immediately drop to the ground.
    This presents a much smaller target to your opponent, reducing his chance of hitting you. Also, it presents motion perpendicular to the line of fire, a ‘moving target’. Moving toward one’s opponent may feel like presenting a moving target, but since you are moving directly along the line of fire, your opponent can fire at the same point and still hit you. Essentially, you’re still a stationary target.

    2) Aim.
    Now that you are on the ground (crouching, kneeling, or prone) and not moving, you can use a two-handed grip and brace. This provides a much more stable firing position than one-handed while running. A very brief time spent aiming, even less than a second, also greatly increases your chance of hitting.

    3) Fire.
    Once you have aimed, don’t wait to fire. Waiting gives your opponent time to adapt to your strategy and more time to fire. Since you’re holding still and have already aimed, your chance of hitting isn’t likely to increase any further.

    Of course, we’re talking about a movie. This approach isn’t very interesting on screen, so you’re unlikely to see it much. I’ve used this method effectively in non-lethal situations, and have been blessed with never having to use it with live ammunition.





Previous post:

Next post:

Other posts you may enjoy reading: