Wednesday 16 September 2015

Hacking the Fort Boyard game and always winning



Do you remember that game from Fort Boyard?
Where you play against the "Maître des ténèbres" removing sticks until only one remains?

If you don't remember no problem, check out the video below:
https://www.youtube.com/watch?v=tng717lJlnA

So, basic rules of the game are:
1) There are 20 sticks
2) Game is turn based. You start first, then it's turn for the "Maître des ténèbres", then yours again...
3) You can remove either 1,2 or 3 sticks
4) If it's your turn and 1 stick remains you lose (the same principle applies for the other player)

So, can we win at this game?
In fact, you can ALWAYS win against the "Maître des ténèbres". There's just a bit of game theory involved, let's see how!

Let's analyse the game. We denote the number of remaining sticks by the variable n.
Let's assume it's currently our turn for different values of n to see what happens:

When n=1, we LOSE.
When  n=2, we can remove 1 stick and can WIN.
When  n=3, we can remove 2 sticks and can WIN.
When  n=4, we can remove 3 sticks and can WIN.
When  n=5, Oops. We don't have the choice: removing 1,2 or 3 sticks will bring us to n=2,3 or 4. So, the other player can win (if he makes the right choice) and we LOSE.
When n=6, interestingly, we can remove 1 stick. This will bring the opponent to n=5 where he loses, so we can WIN.
When n=7, again, we can use the same trick and remove 2 sticks. This will bring the opponent to n=5 where he loses, so we can WIN.
...

If you continue the above procedure, the following pattern will emerge (where L represents Losing and W, winning):
n
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
?
L
W
W
W
L
W
W
W
L
W
W
W
L
W
W
W
L
W
W
W

It seems that every 4 steps is a losing position and we can easily derive that any number of the form:
4k + 1 is a losing position while other values are winning positions.

What's happening here?
What does it mean to be on a winning or losing position as in the table above?

In game theory, we always assume that the two players play optimally. That is, if there is a way to win according to the rules of the game, the optimal player will win.

To be on a winning position means that I can always make a move which forces the other player to "land" on a losing position. Since I'm an optimal player, I will make such a move if it's possible.
In our game above, when we are not on a position of the form 4k+1we can always move to such a number by removing 1, 2 or 3 sticks.

To be on a losing position means that whatever choice I make will bring the game state to a winning position for the next player. Even if I'm an optimal player, I can't do anything about it - the other player is as smart as me and he will always make optimal choices and win.
In our game above, when we are on a position of the form 4k+1we can only move to a number that is NOT of the form 4k+1. That's our only possibility.

That's interesting, now let's apply the rules to see how it works in practice.

It's your turn and the game starts with 20 sticks.

20 is a winning position (it's not of form 4k+1). So if we apply the rules optimally, we must win!
We need to bring the opponent to a losing position (of the form 4k+1). 17 is the one - so we remove 3 sticks.
Now whatever choice the player makes, we repeat the same logic above.
If he takes 1 stick, you take 3 sticks.
If he takes 2 sticks, you take 2 sticks.
If he takes 3 sticks, you take 1 stick.
Now, this will force him to reach 13 sticks, another losing position.

We continue the same procedure until the opponent reaches 1 stick and he loses.

Amazed? This is in fact the basic principle used in 2-player games.
You can apply this principle of forcing the other player to stay on a particular "losing" state to many games. As the game state becomes smaller and smaller, the opponent will eventually reach the smallest possible state (which is still a losing position) and lose the game. The difficulty usually lies determining which states are winning and losing ones by deriving a proper formula.

7 comments:

  1. I knew it! You are the "Maître des ténèbres" in disguise!

    ReplyDelete
  2. Thats how we got kicked at a fancy fair back in 2012 :v

    ReplyDelete
  3. Replies
    1. Thanks Selven!
      The same principle can be applied to the parity problem posted earlier :)

      Hint: consider the parity of the X-distance between the thief and you(police) if you start from X=1 and move 1 step to the right in each hour until X=N :)

      Delete
  4. Good post. Brings back memories, Yog and I used to play this game years ago.

    ReplyDelete