# Nim game

## Running the game

To run the program just launch : `python3 game.py`

## Rules

This game is inspiring from the Nim game. You are 2 players face to face, you have 11 sticks in front of you :

```          \o/
|
/ \
#######################
| | | | | | | | | | |
#######################
\ /
|
/o\
```

The goal is NOT take the last stick !! Originally, this game can be automatize by classical computer to always loose again a computer or against someone knowing the strategy. But what happens if we implement quantum rules ?

Like the original game each player can take 1 to 3 sticks each turn but this time, they can say if they want to take the stick normally, put it in superposition or creating an entanglement between this stick and the sticks previously on the board (played before) :

Symbols table name means action possible ?
| stick left a simple sticks any action
/ superposition stick sticks in states : |0> + |1> no action (only here for info)
¬ entangle stick the faith of this stick depends of the previous one no action (only here for info)
[ ] blank space the previous stick has been fully taken an cx action can be done with if it’s not the first turn of the circuit generation

Here each stick correspond to a qubit at the `|0>` state.

Example of a game : 11 sticks in board : `| | | | | | | | | | |`
1st turn :
Robin choose 2 sticks

• Robin apply an x gate the 11th stick
• Robin apply an h gate to the 10th stick

9 sticks in board : `| | | | | | | | | /`
Batman choose 3 sticks

• Batman apply a cx to the 9th stick (now the 9th stick is automatically link with the 10th)
• Batman apply a x gate to the 8th stick
• Batman apply a x gate to the 7th stick

6 sticks in board : `| | | | | |`

etc …

2 sticks left : `| | ¬`
Robin choose 1 sticks

• Robin apply an x gate to the 2nd stick

1 sticks left : `|`
Batman choose 1 sticks

• Batman apply an x gate to the last stick

When it doesn’t have a stick anymore we run the circuit we create with the gates and get the result, for each qubit still at the state `|0>` we had 1 stick left. Then we continue wit the sticks remaning until we don’t have stick at all after running the circuit.

## Modes

### 2 players

A 2 players mode is available is you want to play with a friend or with your cat

### 1 player

A 1 player is available and you’ll fight against a quantum ia made with a quadratical equation, QAOA and Grover.

View Github