You are on page 1of 17

  

A magazine for the mathematically curious

Read the magazine  Crossnumber  Order  Get involved  About us 

The maths of Mafia   

Sophie explores the fascinating mathematics behind the games


Mafia and Among Us.

by Sophie Maclean. Published on 1 May 2021.

It was 8pm on a wintry Saturday and I was pleading for my life.


“I would never betray you. I promise.” I searched desperately
for someone, anyone, to back me up. Of course, they were right.
I had been responsible for the murder of many of their friends
but I wasn’t about to admit to that. My co-conspirators had
gone quiet, well aware that to support me was to put themselves
into the firing line. At 8.55pm a vote was held. By 9pm I had
been executed.

OK, so that first paragraph may have been a bit misleading.


Thankfully I was not actually put to death, and I haven’t killed
anyone in real life. This all happened whilst I was playing Mafia.
For those unfamiliar, Mafia is strategy game in which players
are (secretly) assigned to be either citizens or mafia. The game
is split up into day and night phases (when playing in person,
night is simulated by everybody closing their eyes). During the
night phase, the Mafia are able to communicate with each other
and can vote to kill one person. During the day phase, all the
residents (both citizens and mafia) discover who died, and then
vote to execute one resident. The aim for each group is to
eliminate the other.

Some of you may be reading this thinking “Hmmmm this is sus.


It sounds very much like Among Us” and you’d be right. The
popular online game was inspired by Mafia and is one of many
adaptations of the game. The particular version I was playing—
when I was outed as a Mafia member—was Harry Potter
themed (if there’s one thing you’ll learn about me during this
article, it’s that I’m incredibly cool). People found themselves
either on Team Hogwarts or Team Death Eater, and there were
some special Potter themed rules, which led to an interesting
situation mathematically.

At the beginning of the game, Voldemort was allowed to select a


horcrux. This essentially meant that Voldemort could not die
until both he and this other character were killed. The crucial
part of this power was that the horcrux didn’t know they were
the horcrux. Towards the end of the game, there were four
characters left alive: Voldemort, Fred Weasley (who was the
horcrux), Fawkes the phoenix, and Ginny Weasley. By this
point, everyone knew for certain which character had been
assigned to each player. Fred, Fawkes and Ginny had also
worked out that one of them was the horcrux but didn’t know
who. They had guessed it was Fawkes. That night Voldemort
attempted to kill Ginny (though didn’t succeed because magic).
The next day, Team Hogwarts were informed of the failed
assassination. What should they do next?

The Great (Monty) Hall


On the face of it, there seems to be no reason to alter who they
suspect the horcrux is. The probability of Fawkes being the
horcrux hasn’t changed, right? Well actually, wrong. When they
settled on Fawkes, there was a 1/3 chance that he was the
horcrux. In attempting to kill Ginny, Voldemort had shown that
she wasn’t the horcrux (Voldemort could equally have
attempted to kill Fawkes here). So the probability that Fred is
the horcrux is 2/3. Therefore it’s best to kill Fred (sorry Fred!).
Though at first glance, the situation doesn’t appear to have
changed, the addition of new information means it actually has,
and in Mafia information is crucial.

Those of you familiar with a


certain piece of mathematical
lore will now be jumping out
of your seats. This is
equivalent to the infamous
Monty Hall problem. In that
problem, a contestant must
pick one of three doors as part
Harry Potter in the Great Hall during a
of a game show. The
feast.
contestant is told that behind
two of the doors is a goat, but
behind the third is a car. After they have made their choice,
Monty Hall (the presenter) opens one of the other doors to
reveal a goat. The contest is then given the opportunity to swap
doors. In our Mafia analogy, the horcrux is the car, with the
other two characters being goats. Voldemort is our Monty Hall,
and by attempting to kill Ginny he opens the door to a goat. And
just like in our Mafia version, the contestant is better off
swapping doors. If this is taking a while to get your head
around, consider the following table (now framed in terms of
the Monty Hall problem):

Swap? initial guess final guess

  car car!

Don’t swap goat 1 goat 1

goat 2 goat 2
Swap? initial guess final guess

  car a goat

goat 1 car!

Swap
goat 2 car!

Each of the initial scenarios (ie each line) is equally likely to


occur. You can now clearly see that when swapping, the
contestant wins 2/3 of the time, compared to only 1/3 of the
time when staying put. Another way of putting this is that to
win when sticking with your first guess, you have to guess
correctly first time (which has probability of 1/3) but to win if
you swap, you have to be wrong on your first guess (which has
probability of 2/3).

This whole scenario got me wondering how else maths could


help when playing Mafia. I first learnt to play Mafia at maths
camp (I told you I was cool) so I knew it was popular with
mathematicians. Could it be that there’s a secret mathematical
strategy to guarantee that you win the game?

Rules and Regulus-ions Black


In short, no. One of the great things about Mafia is there’s a
huge psychological element. When playing with people you
know well, you can observe changes in behaviour that indicate
they’re lying—you can spot contradictions in alibis, you can
notice voting patterns and compare that with known
friendships. Interrogations can be carried out, pressure can be
applied; I’ve even known someone to threaten to end a
relationship if it transpired her partner was lying to her. But
this doesn’t mean that there’s nothing we can say. If we take
out the psychological aspect, and assume that murder choices
are truly random, we can give a probability that the mafia win.
The first step in exploring the maths of any game is to clearly
set the rules, and formalise our mathematical model. We will
consider a simple version of the game, where everyone is either
a mafia member or a citizen and there are no Potter-esque
powers. Let’s define the game as follows:

There are initially N players, all of whom are called


residents. There is also one more person, not playing, who
coordinates the game (this allows anonymous and
simultaneous votes)
Before the gameplay begins, M of these N players are
assigned to be mafia. The remaining N − M players are
citizens.
Every player is told their own identity. The mafia are also
told the identities of each other. The citizens only know their
own identity.
A turn is defined as a day phase, followed by a night phase:
A day phase consists of a debate, where all players can
freely discuss strategy. After this there is a vote where
all players simultaneously choose a resident to execute.
The resident with the most votes is killed. In the event
of a tie, one of the most voted residents is randomly
chosen to die. It is then revealed whether this resident
was a mafia member or not.
A night phase consists of only the mafia
communicating and then voting on which citizen to
kill, followed by their death. In this model, there is no
way for this death to be prevented, and the mafia
cannot kill one of their own.
We assume no psychological aspect comes in to play, and so
we assume citizens never have any information on who is
and isn’t mafia (obviously this is a vast oversimplification
because if, for example, a group of people exactly the same
size as the mafia always vote the same way, and never vote
for each other, even the least observant player may get
suspicious.)
The game continues until only one team (citizens or mafia)
remains and this team is declared the winner.
We will assume every player plays rationally and always
makes the decision that maximises their chance of winning.
This is perhaps the biggest assumption of all.

Let us write the current state with


n players and m mafia as (n, m).
Let the probability of the mafia
winning when there are n players
Regulus Black (Sirius’s late and m mafia be w(n, m).
brother) during the day phase
(left) and the night phase (right)
There are a few things that we can
immediately say, without much
further calculation.

During a single turn, the possible transitions are (n, m) →


(n − 2, m − 1) (when the residents execute a mafia member)
or (n, m) → (n − 2, m) (when the residents execute a citizen).
Fans of Chalkdust may recognise this as a Markov chain (which
you can read about in issue 12). One key thing to note here is
that the number of residents decreases by 2 each turn, therefore
the game must end in a finite number of turns. By putting a
time limit of the length of each phase, you can also guarantee
the game ends in finite time. It would be very unsporting for the
last remaining mafia member to refuse to stop talking and
allow a vote to occur, thereby ensuring that although the mafia
couldn’t win, they also couldn’t lose, but it wouldn’t be unheard
of (looking at you, MPs).

Now we want to consider some probabilities. The probability of


the mafia winning from each state is independent of what
happened before. We can therefore say that

w(n, m) = P (mafia executed ∣ n players, m mafia)w(n − 2, m − 1)


(1)
+ P (citizen executed ∣ n players, m mafia)w(n − 2, m).

Here, P (A ∣ B) is the probability of A happening if B has


already happened (check out this article for more on conditional
probability).

Sorting into houses cases


This is still a fairly general formula, and doesn’t give much
insight. In order to say more, we’ll need to look at three
separate cases:

m > n − m (the mafia have a majority)


m = n − m (there are an equal number of mafia
members and citizens)
m < n − m (the citizens have a majority)

Firstly, let’s look at when the mafia outnumber the citizens. In


this case, the mafia are guaranteed to win. This is because
during the day phase, they can all vote to kill the same citizen,
win the majority vote, and ensure it is a citizen that is killed.
This can be organised during the night phase. Therefore
w(n, m) = 1 when m > n − m.

What about if the citizens


have a majority (ie
m < n − m)? In our
model, the citizens have
no information on who is
and isn’t mafia. Therefore

Sorting into cases their strategy can only be


to randomly select a
resident to eliminate each
day phase. The debate phase can be used to agree on which
random resident to execute (for example using a random
number generator). The citizens then all vote for this person,
and (because they have the majority), the unlucky resident is
executed. There’s nothing the mafia can do to change that. Each
resident has an equal chance of being selected. Therefore the
probability that a mafia member is executed is m/n, and the
probability a citizen is executed is (n − m)/n.

The case when m = n − m (ie n = 2m) is a special case. The


citizens and mafia can propose a player each, and then one of
them will randomly be executed. The probability that a mafia
member is executed is therefore 1/4 (and so the probability a
citizen is executed is 3/4). If a citizen is executed, the mafia
outnumber the citizens, and so they win. If a mafia member is
executed, there remains an equal number of mafia and citizens
(as a citizen is killed during the night phase). This puts us in
exactly the same situation as before, with the same
probabilities. For the citizens to win, a mafia member must be
executed on all remaining turns (of which there must be m as
two residents are killed per round). Hence P (citizens win) =

(1/4)
m
= (1/2)
2m
= (1/2)
n
, and so w(2m, m) = 1– (1/2)
n
.

If we combine all this, and use (1), we get the following:

⎧1 if m > n − m

n


1
⎪ 1– ( ) if m = n − m
⎨ 2
w(n, m) =


m n − m


⎪ w(n − 2, m − 1) + w(n − 2, m) otherwise.
n n

This is pretty neat and is now just an iterative equation. It would


be perfectly possible to calculate w(n, m) now, by just plugging
through the steps (or even writing some code to do it for you if
you’re that way inclined). Finding a more general formula
becomes pretty complicated pretty fast. But there is still more
that we can say, without our brains hurting too much.

(The philosopher’s st)one mafia member


Let us consider the game with only one mafia member. In order
for this mafia member to win, in every day phase a citizen must
be executed. Remember that day phases precede night phases.
Therefore
n − 1 n − 3 1 + n (mod 2) (n − 1)!!
w(n, 1) = × ⋯ × = . (2)
n n − 2 2 + n (mod 2) n!!

Here !! is the double factorial function (like factorial, but taking


every other element). It’s worth noting that because n (mod k)

is the remainder when n is divided by k, we have

0 if n is even
n (mod 2) = { (3)
1 if n is odd.

This highlights a rather interesting property: the dependence


on the parity of the number of residents. This doesn’t seem
unreasonable, because two players are killed each day, and
whether there are an even or odd number of players does affect
the proportion of players needed to have a clear majority. A
quick calculation using (2) shows that w(2, 1) = 1/2 and
w(3, 1) = 2/3. In the second case, despite there being a greater
proportion of citizens, the probability that the mafia win is
actually higher.

In fact, with a single mafia member, it is always true that


adding an extra citizen to make the total number of players odd
increases the mafia’s chance of winning. We can prove this by
induction.

Proof by induction
We use w(2, 1) and w(3, 1) as our base case. Our inductive
hypothesis is that w(2k + 1, 1) > w(2k, 1). Let’s now
consider

2k + 2
w(2k + 3, 1) = w(2k + 1, 1).
2k + 3

It is true in general that (a + 1)/(a + 2) > a/(a + 1) for all


non-negative a (if you don’t believe me, you can try proving
it yourself). Therefore
2k + 1
w(2k + 3, 1) > w(2k + 1, 1).
2k + 2

Now we apply our inductive hypothesis to get

2k + 1
w(2k + 3, 1) > w(2k, 1)
2k + 2

= w(2k + 2, 1)

which is exactly what we want and completes our inductive


step. Therefore w(2n + 1, 1) > w(2n, 1) for all n > 0.

So now we’ve shown that the mafia’s chance of winning is


higher with an additional citizen making the total number of
players odd, which I found pretty surprising. So you can only
imagine how shocked I was when I learned that the parity of the
number of players has such an effect that w(9, 1) > w(4, 1). In
fact, we can plot a graph of w(n, 1) for odd and even n using our
expression in (2) to highlight this:

A graph of w(n, 1) against n for n odd (green), and n even (blue).

Time to get Sirius


And now we can reach the limit of what I can explain without
writing a thesis. Luckily for me, Piotr Migdał has written a
paper for his bachelor’s degree. There is one main result from
that, extending the ideas above, which I’d like to share with
you. It considers the case of there being multiple mafia
members.

In a similar way to how we derived w(1, n), Migdał shows that

m
m (n − i)!!
w(n, m) = 1– ∑ ( ) .
i n!!((n (mod 2)– i)!!
i=0

Now observe that (n − i)!!/(n − 1)!! → 0 as i increases.


Therefore only the first two terms of the sum contribute
significantly. Hence we can write

(n − 1)!!
w(n, m) ≈ m . (4)
n!!

To write this in a nicer form involves a few neat ideas. One fact
that will prove very useful is that for any k,
(2k + 1)!! = (2k + 1)(2k − 1)!! (using the definition of double
factorial above).

We first consider the product of w(2k + 1, m) and w(2k, m).


By (4), this gives:

m(2k)!! m(2k − 1)!!


w(2k + 1, m)w(2k, m) ≈ ×
(2k + 1)!! (2k)!!

m(2k)!! m(2k − 1)!!


= ×
(2k + 1)(2k − 1)!! (2k)!!

2
1
= m . (5)
2k + 1

Now we’re going to look at w(2k + 1, m)/w(2k, m), again


using (4). This may seem a bit odd right now, but trust me on
this one.

w(2k + 1, m) m(2k)!! m(2k − 1)!!


≈ ÷
w(2k, m) (2k + 1)!! (2k)!!

2
(2k)!!
=
(2k + 1)!!(2k − 1)!!

2
(2k)!!
=
2
(2k + 1)(2k − 1)!!

2
(2k)!! 1
= ( ) . (6)
(2k − 1)!! 2k + 1

At this point, you’d be forgiven for having your doubts that I’m
making anything more simple here. Fear not! It all becomes
clear with the introduction of the Wallis formula:

2
π (2k)!! 1
= lim ( ) .
2 x→∞ 2k + 1
(2k − 1)!!

We can now write (6) in the limit k → ∞ as

w(2k + 1, m) π
≈ . (7)
w(2k, m) 2

Okay, we’re nearly there. I promise. The final clever idea


requires considering even and odd n separately. Write n = 2k

for n even (where k is a positive integer). For n odd, write


n = 2k + 1 (again for a positive integer k). Now here’s the
magic. Write:

−1/2
⎧ w(2k + 1, m)


( ) √w(2k + 1, m)w(2k, m) for n = 2k (ie n is even)


w(2k, m)

w(n, m) = ⎨


1/2

w(2k + 1, m)


( ) √w(2k + 1, m)w(2k, m) for n = 2k + 1 (ie n is odd).


w(2k, m)
Substituting in our values from (5) and (7) above gives

⎧ −1/2 2


π m




( ) for n = 2k


2

2k + 1

w(n, m) ≈ ⎨


π 1/2
m
2


( ) √ for n = 2k + 1.


2 2k + 1

This can be put in to a single line by recalling (3), and using the
fact that for large k, 2k + 1 ≈ 2k:

n (mod 2)–1/2
π m
w(n, m) ≈ ( ) . (8)
2 √n

So we finally have an approximate expression for w(n, m).


Phew. From this, it’s only a small step to calculate how many of
the n players need to be made mafia initially in order to give the
two teams equal chance of winning.

To do this, we set w(n, m) = 1/2 in (8). Hence we find the


optimal value of m is approximately

n (mod 2)+1/2
√n π
( ) .
2 2

This is particularly interesting as it means that when creating a


game of mafia, you can choose the initial number of mafia to
ensure that the mafia (or the citizens) are unlikely to win by
luck alone, and some skill has to be involved. Unfortunately
though, this gives no indication of what that skill should be.
A fair game with 13 people (during a night phase): 3.55 mafia
members (top) v 9.45 citizens (bottom). In a real game,
however, it will probably be easier to round the number of
people on each team to the nearest integer.

One final thing that I’d like to point out is the effect of the
parity of n on w(m, n) and the optimal value of m. We saw in
the case of one mafia member how much of difference it makes,
and we see it again here. It becomes even clearer when we plot
the optimal value of m against n:

A graph of the optimal value of mafia m against n for n odd (green), and n
even (blue)

So there we have it: I don’t have any surefire winning strategy


to reveal to you. But in a way, that’s what I love so much about
Mafia. Yes, maths can be used to play the game better, or to give
an idea of how to structure a perfect game, but maths doesn’t
give a way to guarantee you’ll win. It can inform wiser choices,
but ultimately it comes down to how much you trust your
friends. And if there’s one thing I’ve learnt playing Mafia, it’s
that you can never truly trust your friends.

Sophie Maclean
Sophie Maclean is a recent maths graduate from
the University of Cambridge and very much
misses her degree. She has no free time—she is a
Chalkdust editor.

+ More articles by Sophie

More from Chalkdust

The big argument: Is In conversation with


dy/dx notation better Ulrike Tillmann
than y’ or ẋ? Sophie Maclean and David
The Leibniz–Lagrange– Sheard speak to a very
Newton showdown we all top(olog)ical mathematician!
want to see

On conditional Who is the best


probability: Cards, England manager?
Covid, and Crazy Rich Paddy Moore levels the score
Asians
Madeleine Hall explores the
sometimes counterintuitive
consequences of conditional
probability to our everyday
lives.

The big argument: Is How to be the least


the Einstein summation popular American
convention worth it? president
We hear arguments for and Francisco Berkemeier takes a
against this controversial look at the mathematics be-
convention hind elections, and the Elect-
oral College, in the United
States of America.
Read also

The big argument: Is dy/


notation better than y’ o
The Leibniz–Lagrange–Newt
showdown we all want to see

In conversation with Ulr


Tillmann
Sophie Maclean and David She
speak to a very top(olog)ical
mathematician!

On conditional probabili
Cards, Covid, and Crazy
Rich Asians
Madeleine Hall explores the s
times counterintuitive con-
sequences of conditional prob
ity to our everyday lives.

@chalkdustmag
Tweets by
‎@chalkdustmag


chalkdust Retweeted

John Golden
@mathhombre

Best recurring #mathjoke


segment from
@chalkdustmag
chalkdustmagazine.com/regul
ars/dear-…

Dear Diri…
Football, …
chalkdust…


27 Nov 2021


chalkdust Retweeted

Peter Rowlett
@peterrowlett

With the arrival of


#chalkdust14, I thought I’d
check how many issues of
@chalkdustmag I have. Turns
out I have all issues except 1
and 2.

Embed View on Twitter

Chalkdust is published by Chalkdust Magazine, UCL, Gower Street, London WC1E 6BT, United Kingdom. ISSN 2059-3805
(Print). ISSN 2059-3813 (Online).

You might also like