With the exception of Super Meat Boy, I don’t know if any game frustrates me as much as Mario Kart. There are times at which it seems the game is deliberately conspiring against you in the cruelest way possible: the ill-timed lightning strike that sends you into the abyss, the clairvoyant green shell apparently steered towards you by the hand of Miyamoto himself and, of course, the last-minute blue shell that renders void your furious battle for first place. I can recall vividly an instance of being hit by a blue shell followed by three red shells about ten seconds from the finish line on Sunshine Airport, sending me from a comfortable first to a slightly less comfortable tenth.

At times like this, it can feel like your prowess as a driver is largely immaterial as far as actually winning is concerned, and that the way to succeed is to ‘*play the game*‘ along with everyone else; that is, to shell, bomb and boomerang your way to victory. Why bother trying to outrace the player in front of you when you can simply blast them out of the way? In this post, I will discuss the role of playing defensively using some toy models. These models are enormous simplifications of a real game, and so there is only a limited amount to discuss, but I hope they will get the key ideas across.

**Mathematical Model of an Encounter**

We’re first going to look at a very simple mathematical model of a single encounter during a race. It will, in brief, express mathematically the intuitive reasons for why defensive play might be advantageous.

We have three players in positions n-1, n and n+1. We will assume they are sufficiently closely spaced that they pass through a set of item boxes at approximately the same time, and that the distribution of items will be roughly the same for all of them. This distribution, in turn, will be simplified enormously by dividing it into items that can be used both offensively and defensively, and those that cannot. Examples of items that fall into the former category are bananas, boomerangs, green shells and red shells; of these, we will take the red shell to be the ‘canonical’ example, since they are easiest to use offensively.

I’ll introduce two probabilities, and . The former is the probability of the players gaining a red shell on passing through the item boxes. The latter is the probability of their playing ‘aggressively’, i.e. firing their shell if they see an opportunity to do so. I will also introduce the integer , the number of places lost by any one of the players if they are hit by a shell.

Suppose the central player gains a red shell. We would like to answer the question: **what is the mean number of places they gain by launching their red shell?**

For this calculation, we need to know all possible outcomes of this three-player encounter. For brevity, the player in front of the central player will be called A, the player behind B, and the central player themselves C. The table below describes the possible consequences of C firing their shell:

The mean change in position is defined as the sum of all possible changes in position weighted by their associated probability. The table above tells us that

Simplified, the above reads

We can unpack this by plotting a graph of against for several values of . The resulting family of curves for = 2 is shown in the diagram below. Let’s see how changing each variable affects the mean change in position.

First, consider the effect of changing . We see that the greater (i.e. the more aggressive the other players), the more likely C is to lose a place (and vice versa). It therefore pays to be defensive in a hostile environment, and to be hostile in a defensive environment. How can we implement this information? It’s tricky to assess how aggressive your co-players are without racing with them frequently. However, you might guess that players who are *close to last place* (perhaps having been hit by a barrage of items recently) will play more recklessly than those leading the race. People tend to get fairly nasty in the midfield too: the high density of targets makes firing your shell very tempting. It may therefore be prudent to play defensively when close towards the back or middle of the pack, and up your aggression as you move forwards.

Now consider the effect of changing . The greater (i.e. the better armed), the more likely C is to lose a place (and vice versa). This is a fairly intuitive result! So where are players best armed? Red shells, at least, have their probability of acquisition most strongly peaked an intermediate distance from the race leader, i.e. in the midfield. This would suggest playing defensively is the way forward when close to the middle of the pack.

In summary, our simple equation reproduces the intuitive result that red shells are better used as shields than weapons when i) in a more hostile environment and ii) in an environment where your opponents are better armed. It seems obvious when you state it this way, but that does not stop many players firing a red shell as soon as they acquire it close to the midfield.

We can go a little further than the general statements above. A ‘mean mean’ change can be extracted by integrating over all possible values of the probabilities and :

This number drops below zero when (the number of places you lose on being hit by a red shell) is a little greater than 2. Clearly, this average continues to decrease the greater is, and the reason for this is clear: there is a fundamental asymmetry between the use of the red shell as a weapon and as a shield. If you hit the player in front of you with a shell, you gain one place. If the player behind you hits you with a red shell, you will likely lose more than one place. In this respect, is a function of the local player density, but that’s another discussion entirely …

I think it’s important to make these sorts of considerations when deciding whether or not to use your red shell. As a simple example, suppose you *know* the person in front of you has a red shell. Clearly, the most sensible thing to do is to wait until they fire, and then fire upon them (this way, you could potentially overtake two players). A trickier decision is whether to fire upon the person in first place with a red shell when you know they’re undefended. Is it better to wait until a blue shell takes them out, or do you stop them quickly before they can pull away further? This is almost a primitive form of *game theory*, and (I think) adds another layer of complexity to Mario Kart that makes it all the more enjoyable.

**Simulation of a Full Race**

A race comprises not one, but very many encounters of the type discussed above. To get a real handle on this problem, I wrote a computer program that simulates a race (albeit a highly simplified one!) and monitors the progress of a single player with user-defined attributes. I’ll describe the program in a little more detail before discussing the results.

The simulation models twelve players driving along a rectangular track, where the -coordinate measures distance ‘along’ the track. The equations of motion governing the players’ coordinates read

where is a constant that is changed every few seconds. The first equation causes the cart to accelerate up to some maximum speed over a timescale . The second equation causes the cart to randomly drift across the width of the track. The constants and are the same for every cart.

Item boxes are placed across the track at equal intervals in the direction. On passing through the boxes, each cart can become equipped with a red shell or, infrequently, a blue shell. If a cart gains a red shell, it will choose whether to fire the red shell at the player in front (with probability ), or to use the red shell as a shield (). The probability therefore characterises a player’s aggression, with = 0 corresponding to a player that *never* fires a red shell, = 1 to one that *always* fires. These probabilities are overridden if the player is in last or first place, in which cases they are guaranteed to fire or use their red shell as a shield respectively.

Here is a snapshot of the simulation’s graphical output (click for a higher-resolution view):

Players are marked by green and blue smiley faces. The player marked by the golden face is the one that is monitored. You can see two travelling red shells and a blue shell in the bottom-left region of the track. The infinitely-long rectangular track has been mapped onto a stadium shape to make viewing easier.

To evaluate the effect of playing with higher or lower aggression, simulations were performed with one of the players (the gold one) having a different probability to the others. The ‘ambient’ aggression was chosen to be 0.75, which is to say that all but one of the players had a 75% chance of firing a red shell on passing through an item box. The gold player was chosen to have = 0.00, 0.55, 0.65, 0.75, 0.85 and 1.00 for ten simulations each. I monitored the position (ranging from 1st to 12th) of the gold player from last place during each of the simulations. The profiles were subsequently averaged over the ten simulations for each value of . The graph shows the average position of the gold player over time for a variety of aggressions:

In our simple model, the more defensive the player is, the better its performance. Indeed, if the player never fires a shell, it is practically guaranteed to win. Why does this happen? Well, in our heavily simplified simulation, the *only* way a player (not in first place) can be hit is to be hit by a red shell from the player directly behind. The player that never fires a red shell can therefore *never be hit. *Now, despite the fact that our gold player never attacks the player in front and does not travel any faster than them, it *will* eventually overtake them. Why? Because these players will likely be attacking one another, and therefore slowing one another down. Even in the unlikely event that they are all using their red shells as shields, blue shells eventually will whittle them away, leaving the gold player to take first.

Unfortunately, the simulations above aren’t particularly realistic: you can never maintain invincibility in Mario Kart. You might get targeted by three red shells, or by a boomerang, or a bob-omb, none of which can be blocked by a single shell trailing behind you. Constantly hanging on to shells also means you could be missing out on mushroom boosts, meaning your average speed is reduced compared to your more aggressive co-players.

This doesn’t render our simulations useless, though. Let’s try to account for the second of these two effects. In this second set of simulations, the speed of the gold cart is reduced by 5%. The odds are now slightly stacked against the gold player, since every other player travels a little faster than they do. Is it now advantageous for the gold player to play aggressively, to make up for their handicap? The graph below shows their average position over time for a range of aggressions close to 0:

Even now, the defensive player fares better than the aggressive player. Though the pacifist is not guaranteed first place this time, they can maintain a reasonable sixth place without firing a single shot. How? The other players do all the work for them! They blast one another with shells and slow one another down, allowing the pacifist to drift serenely past them. These simulations, I think, highlight this point quite well, to which I alluded in my conclusion of the previous section: you needn’t take out the players in front of you yourself, because you can often trust someone else to do it for you.

That concludes my thoughts on playing defensively in Mario Kart. To be honest, my goal was not so much to prove one point or another, but to see how easily Mario Kart lends itself to analysis. From the little work I’ve done, I’ve gained the impression that a great deal could be learnt by making the simulation program only a little more sophisticated. For example, additional items could easily be introduced, as could an item probability distribution, which would simulate more faithfully the relatively dangerous environment of the midfield. If you’ve any thoughts on either analysis or tactics, I would be glad to hear them in the comments.

Happy karting!

*This is the second of two posts on Mario Kart Maths; see the first post here.*