Quantum games work in a similar way like games that involve an element of probability. Consider a game where different players have to beat a house or referee. The players are not allowed to communicate with each other during the duration of the game and have to prepare a strategy in advance. To win, the outputs or results given by the players have to satisfy a certain condition or rule of the game. In this tutorial, we will build and play a quantum game by exploring different classical and quantum game strategies.

Similar to classical computation, quantum computation can be performed using the circuit model of computation, applying different logic gates . Qubits are the analogues of bits and quantum gates operate on qubits, whilst manipulating quantum mechanical properties . What makes a quantum gate special is its reversibility. In order to have reversible quantum gates, we need to implement it using unitary operations; operations which preserve the sum of the probabilities of seeing each measurable value of the qubits. The sum of the probabilities of each outcome must add up to 1.

In quantum computation the objects of the computation are quantum objects called qubits. Qubits are represented as |0⟩ and |1⟩. The qubit state |Ψ⟩ can be expressed as a superposition of |0⟩ and |1⟩, or |Ψ⟩=a|0⟩+b|1⟩ where a and b are complex numbers, proportional to measuring the probability of its corresponding outcome.

More specifically, the probability of measuring the qubit state as |0⟩ is a^2 and |1⟩ is given by |b|^2

respectively. Another interesting property that we must know of is entanglement, which Einstein described as "spooky action at a distance". If two qubits are entangled with each other, then if we know the value taken by one of them, then without even observing the second qubit we know it's state/value. The correlations between the values of entangled qubits is unique to quantum probabilities and something we cannot perform on a classical computer. In fact, it is not possible to separate an entangled system in to its independent parts. Whenever we want to observe the value of a quantum system, we must make a measurement of their state. This, causes the system to take collapse to one value. It is not possible to determine with certainty which value the system will take, but we can think about the various probabilities for the allowed values.

The most common quantum gates are:

**X gate**: flips the state of a qubit from |0⟩ to |1⟩ and vice-versa

**Z gate**: flips the phase of a qubit (changes relative sign of a and b)

**Y gate** : flips the state of a qubit and its phase.

**H gate:** creates superposition or a linear combination of |0⟩ and |1⟩

**Rx, Ry and Rz** gates: Rotates qubit, by changing the coefficients a and b in a way that depends on the angle of rotation inputted into the gate as a parameter

The most important two qubit gate is the controlled-not gate:

**CX**: flips the state of a qubit on the state of another qubit based on a condition. It consists of a control qubit and a target qubit. If the control qubit is in the state |0⟩, then no operation is performed on the target qubit. However, if the control qubit is in the state |1⟩, then a X gate is performed on the target qubit. Creates an entangled bell pair in combination with the H gate.

Let's make use of quantum properties we just learnt to make our game!

Our game involves two players (Alice and Bob) who play against the house. Alice and Bob are allowed to discuss and pick a strategy before the game starts, but not allowed to communicate after the beginning of the game. A referee generates two random bits **x** and **y** which are given as inputs to Alice and Bob respectively. Alice and Bob do not know each other's inputs. They can manipulate their own input however they wish, according to their strategy, and then choose a bit to output. Alice will output a bit **a** and Bob a bit **b**

Alice and Bob win against the house if the they satisfy the following condition:

In the classical world, Alice can only devise a strategy based on her value of the input bit x and Bob according to its input value y**. **An easy but bad strategy is that they output their input or output the opposite of their input. They can also always input 1 or 0. Can you think of a strategy that will be winning 75% of the time for Alice and Bob?

Alice and Bob play the game by sharing an entangled pair of qubit. Two qubits form an entangled pair and then Alice and Bob are given one of the qubit from the pair.

According to the input they receive from the house they will rotate their entangled qubit using the Rx, Ry and Rz gates we mentioned and then measure it. A bad strategy would be to rotate the qubit by a random amount or the same angle. However, it is possible to find the angle of rotation that maximizes the probability of winning the game, which is around 85%. Read this article to find out more!

There are 3 possible choices the user can pick

1. Don't rotate the qubit

2. Rotate a random amount

3. Rotate to maximize winning probability

Let's start coding!

q_Prob_win is 85%, which is better than if we used a classical strategy to play the game!