Simple C++ program for the 21 game

The game "21" is played as a misère game with any number of players who take turns saying a number. The first player says "1" and each player in turn increases the number by 1, 2, or 3, but may not exceed 21; the player forced to say "21" loses. This can be modeled as a subtraction game with a heap of 21–n objects.
The winning strategy for this game is to say a multiple of 4 and after that it is guaranteed that the other player will have to say 21, barring a mistake from the first player.
This game has a Sprague-Grundy value of zero, i.e., it is biased in favor of the 2nd player as s/he can get to 4 first and then control the game from there, as no matter what, the 1st player will never be able to say a multiple of 4 as s/he is only allowed increments of either 1, 2 or 3.

Proof (via a sample game of 21)-

Player Number
1 1
2 4
1 5,6 or 7
2 8
1 9,10 or 11
2 12
1 13,14 or 15
2 16
1 17,18 or 19
2 20
1 21

I would like to write a program in Turbo C== for this. Would anyone please help me with the algorithm of this program??
Last edited on
Topic archived. No new replies allowed.