Skip to content

Instantly share code, notes, and snippets.

@adamniedzielski
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamniedzielski/13316d4ae53902ea1b30 to your computer and use it in GitHub Desktop.
Save adamniedzielski/13316d4ae53902ea1b30 to your computer and use it in GitHub Desktop.
Wargame

Wargame is about the final battle which will happen soon, but nobody knows when exactly. Two armies are standing just opposite. The generals have to move their soldiers carefully to have the advantage exactly when the final battle begins.

There are two players playing against each other. Each player is a general and has his army. An army consists of soldiers. The game may last from 1 to 10 rounds. Each round consists of three phases:

  1. player A makes a move
  2. player B makes a move
  3. checking

Phase 1) and 2) happen in the same time so player B does not know moves of player A before his own move.

Each army has its camp and its field. So, the situation looks like this:

Camp A ||| Field A ||| Field B ||| Camp B

Each army starts with 20 soldiers in its camp. During his move a player has to decide how many soldiers should move from camp to field. It is the only possible direction, it is not possible to move soldiers from field to camp.

In the checking phase it is determined whether the final battle begins after current round or the game continues. The probability of final battle increases with time to reach 100% in round 10:

  • round 1: 1/10
  • round 2: 1/9
  • round 3: 1/8
  • round 4: 1/7
  • round 5: 1/6
  • round 6: 1/5
  • round 7: 1/4
  • round 8: 1/3
  • round 9: 1/2
  • round 10: 1/1

If the final battle begins then we compare the number of soldiers in field A and field B. The player who has more soldiers - wins. If the game continues then half of the soldiers in field A is killed and half of the soldiers in field B is killed. In case of odd numbers we round the result to the lower number: 3/2 = 1

So - the goal of the game is to have more soldiers in the field than the opponent. However, if you move them too quickly then they will be killed very soon.

Example:

20 ||| 0 ||| 0 ||| 20 starting positions

round 1:
18 ||| 2 ||| 0 ||| 20 player A moves 2 soldiers
18 ||| 2 ||| 4 ||| 16 player B moves 4 soldiers
checking -> no final battle
18 ||| 1 ||| 2 ||| 16 half of the soldiers in the fields is killed

round 2:
17 ||| 2 ||| 2 ||| 16 player A moves 1 soldier
17 ||| 2 ||| 4 ||| 14 player B moves 2 soldiers
checking -> no final battle
17 ||| 1 ||| 2 ||| 14 half of the soldiers in the fields is killed

and so on...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment