I’ve recently been playing XCOM, the new revamp of the classic alien-invasion turn-based strategy series. For those who don’t know the game: you are in charge of XCOM, a force put together to defend the Earth from alien invasion. There’s two aspects to the game: one is an overall management view, deciding what to invest in, what to research, how to equip your UFO interceptors and so on. The other aspect is a turn-based tactical game, moving your squad of soldiers around the battlefield and shooting at the aliens.

Each turn, each soldier has two actions, one of which can be to shoot at an alien. There’s all sorts of other abilities that override this simple rule, but that’s the basic rule: at most, one shot per turn. When you go to shoot, the game tells you the exact probability of your shot connecting:

Your shot either hits or it doesn’t, and then damage is randomly calculated thereafter. But the key thing is whether the shot connects. Waste your chances with 25% shots, and you’ll soon get overpowered. It’s better to maneuver around, destroy the aliens’ cover, and then shoot with an 85% chance. And when it misses, you can exclaim stupid things like “My 85% shot missed! What’s the chances of that!” (Spoiler: 15%).

The turn-based game is a mixture of moving carefully to cover, and managing your odds. Different soldiers may have different odds of hitting the same alien, so you choose who to take which shot on which alien in which order to maximise your chances of success. Effectively, you’re navigating a probability tree, and the skill is in finding the optimal path. Of course, it’s all still random, so even your best strategy can go horribly awry: when your 95% shot misses, and your backup 85% shot misses, you feel slightly aggrieved (exercise for the reader: what’s the chances of that, eh?)

Rapid Fire Chances

There’s also some interesting game mechanics that require a bit of consideration. One good example of this is the Assault class’s “Rapid Fire” ability. This allows you to take two shots instead of one, but at a 15% reduced chance to hit. Obviously, as the player, you want to know: when it is advisable to fire a single shot, versus firing two reduced aim shots? That depends on a couple of other factors: are you worried about using too much ammo at this stage, and will one shot be enough to kill the alien?

Let’s take the simplest case. The alien is infuriatingly still alive, despite having just 1 health, meaning any shot that hits will kill it. You’ve got full ammo, and your Assault has moved to a good location. You have some probability, , to hit the alien with a single shot. Should you fire one shot, or use rapid fire? One shot has the chance to hit. What’s the probability of one of the two rapid fire shots hitting? There’s two ways to think about this, which we can look at with a probability tree:

One is to add up the probability of the different branches: we’re interested in the branch where the first shot hits (and since this will kill the alien, no further shots will occur) and also the branch where the first shot misses and the second shot hits. They are highlighted in red on the tree above, and mathematically, we can calculate the probability of hitting to be , which we can multiply out to . The other method, when you want to find out the probability of at least one event occurring, is to calculate the probability of no events occurring, then “invert” it by subtracting it from 1. The probability of both shots missing, highlighted in blue on the tree above, is , so the probability that at least one hits is , which also comes out to .

So, what we want to know is when , the chance of hitting with two rapid fire shots, is greater than , the chance of hitting with one normal shot. For this, we can use a graph, plotting as the red line and as the yellow line:

The straight red line is the chance of hitting with a normal shot, the curving yellow line is the chance of hitting with at least one rapid fire shot. As you can see, generally it’s better to use rapid fire, except at the extreme ends. What’s happening at those ends? Well, at the low end, say you have a 25% chance of hitting with one shot. The chance to hit with each rapid fire shot is then only 10%, so the chance of hitting with a shot is , which is only 19%: the chance to hit is so awful that you’re better off with a 15% higher chance on one shot. At the very top end, if you have a 100% chance to hit, then that is obviously better than two 85% chances. Of course, the crucial piece of information is what are the two points where the lines cross, which define the region where two shots are better?

To find out where the lines cross, we need to know the value for when . We’ll need to multiply out a bit:











Now we have a quadratic equation for the variable , where , , and . We can plug these in to the quadratic formula:

or

So there you have it: between 34% and 96% chance on a normal shot (inclusive), you’re better off using rapid fire if the alien only needs one shot to kill him (and ammo is not an issue).

Rapid Fire Damage

An obvious next question is what you should do if one shot will not be enough, and you just want to do as much damage as possible. Well, let’s say each shot that hits does an average of damage. It doesn’t matter about critical hits or how damage is calculated — each shot, normal or rapid fire, does the same average damage if it hits, so that’s all we need to think about. The average damage of a normal shot is — the chance of it hitting multiplied by the damage it will do if it hits. The average damage of a single rapid-fire shot is .

So how do you calculate the average damage of two rapid-fire shots? Well, it turns out that it’s quite easy. The two rapid-fire shots are independent events: the chance of the second hitting doesn’t depend on the first. So the average damage of two rapid-fire shots is simply . So the question then is, for what values of is it true that ? The graph this time has two straight lines:

So above a 30% chance for a normal hit, you’re increasingly better off to fire two shots, if what you care about is doing a lot of damage. And in XCOM, if you’re shooting anything with less than a 30% chance, you’re pretty desperate!

Design

As a player, it’s useful to know when rapid fire is actually going to be useful. But bear this in mind, too: the designers almost certainly produced that first graph when designing the game. They had free choice over the penalty being 15% for two shots. What would have happened if they had chosen a 30% penalty? The graph would have looked like this:

With that penalty, you always would have been better off using one shot for a single alien, and you would not have got much better damage when trying to hit with two — most players probably would have skipped the skill and written it off as useless. Thus the choice of the 0.15 reduction was important. Knowledge of probability comes in handy here, both for players and for designers.

You may also want to read a follow-up on how the randomness in XCOM works: Randomness vs Canniness, or Programmers vs Savescummers