YouTube Demo: https://www.youtube.com/watch?v=U6_wSh_-EQc
In this game, 2 players X
and O
are represented by 2 qubit classical states, X
, while the Identity gate represents player O
's unchanged state
-
Classical Move: Each player alternates turns, placing their marker
X
orO
on 1 unoccupied cell. - SWAP Move: Apply the SWAP gate swap the states of 2 occupied cells without adding new markers.
-
Superposition: Apply the Hadamard (H) gate to 1 unoccupied cell (qubit), resulting in the
$|+\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}$ state, which does not commit toX
orO
until the board is measured and collapsed. - Entanglement: Link 2 or 3 unoccupied cells, affecting outcomes such that the final state of one cell will affect the other. Players must also carefully choose between 4 Risk Levels (see below) based on their current position and potential future board states. Lower levels allow more controlled outcomes, while higher ones can gamble for a win or potentially aid the opponent.
The X?
and O?
markers will be used to indicate the cells are superposed/entangled, meaning their final values as X
or O
are not yet determined until a measurement collapses their states and capture the state with the highest occurrence. This can happen when:
- The board is full. If there are still several
X?
/O?
cells, an automatic collapse will be performed to resolve all superpositions. - Reaching a set of superposed/entangled cells forming a potential winning line.
- Manually triggered by the Collapse button press.
[NOTE]:
- If the board is full with no cells in superposition and also no winning lines, the game is
Draw
. - If you want to make a new choice for Entanglement Risk Levels, just click the Entanglement button again.
In the beginning, this game only has 3 options: Classical move, Superposition, and Entanglement with the standard Bell state
-
Firstly, when players select Entanglement and pick 2 cells on the board, this will be unfair for their opponents as they will lose 1 move.
-
Secondly, the Bell state
$|\Phi^+\rangle$ represents a maximally entangled state where measurement outcomes are perfectly correlated ($|00\rangle$ or$|11\rangle$ ). This strategy can be risky as it could lead to either a winning line quicker or accidentally help the opponent. For example, ifX
players have a plan of entangling 2 consecutive cells, they can have:- Multiple
X
in a row, increasing their possibility of winning. - Multiple
O
in a row, putting them at risk of losing as theirO
opponents now have more consecutive cells than them.
- Multiple
Therefore, to overcome these:
- I introduce the SWAP Move, which can disrupt existing lines or defenses in the opponent's strategy, limiting players from overusing Entanglement to dominate the game unfairly.
- Moreover, I introduce 4 Entanglement Risk Levels to add strategic depth and require players to think critically about the consequences of their quantum moves:
- By adding a Pauli-X gate before the CNOT's target qubit, I turned the Bell state
$|\Phi^+\rangle$ into$|\Psi^+\rangle$ , which also represents a maximally entangled state but with opposing outcomes, ensuring a 50/50 chance and reducing the above risk of$|\Phi^+\rangle$ . - Similarly, I further employed the same approach for Triple Entanglement and turn the Standard |GHZ⟩ state into |GHZ_Xs⟩ by applying 2 additional Pauli-X before the CNOT chains of 2 targeted qubit components.
- By adding a Pauli-X gate before the CNOT's target qubit, I turned the Bell state
There are 2 types of Entanglements in this game associated with 4 corresponding Risk Levels:
- Pairwise Entanglement: A player can entangle 2 empty cells, meaning the state of 1 cell depends on the state of the other, and their final states (either
X
orO
) aren't determined until a measurement is performed. - Triple Entanglement: Advanced moves allow entangling 3 cells simultaneously.
Risk Level (Select via the "Dropdown") | Quantum Gates | Example Circuit | Effect on Measurement and Collapse | |
---|---|---|---|---|
Lv1. Lowest Risk
|
Hadamard (H), Pauli-X (X), CNOT (CX) |
|
This Bell state results in anti-correlated and truly random outcomes upon collapse. When 1 qubit collapses to X, the other must collapse to O, and vice versa. | |
Lv2. Lower Risk
|
Hadamard (H), 2 Pauli-X (X), 2 CNOT (CX) |
|
Similar randomness but for 3 squares, formed by modifying the Standard |GHZ⟩, leading to combinations where the outcome isn't uniformly all 3 Xs or all Os, but mixed. |
|
Lv3. Moderate Risk
|
Hadamard (H), CNOT (CX) |
|
This Bell state yields the same outcome for both selected cells/qubits. Both qubits collapse to the same value upon measurement, either XX or OO. | |
Lv4. High Risk
|
Hadamard (H), 2 CNOT (CX) |
|
This Standard |GHZ⟩ state can strategically benefit the player but also at the risk of benefiting the opponent just as much. All 3 qubits collapse to the same value, either all XXX or all OOO. |
1. Install Qiskit and PyLaTeXEnc
pip install qiskit --quiet
pip install qiskit-aer --quiet
pip install pylatexenc --quiet
2. Play the game
from qiskit_aer import AerSimulator
from gui import QuantumT3GUI
game = QuantumT3GUI(size=3, simulator=AerSimulator())
👉 Check this quantum_tic_tac_toe.ipynb for a demo. You should open it in Colab, the notebook viewer within GitHub cannot render the game's widgets.
- Limit the Entanglement Risk Levels based on the board size. For example, 3x3 board can only use PAIRWISE entanglement (Level
1
&3
). Because if they use2
or4
, they can win or lose the game in 1 move. - Count the number of winning lines for each player as a score to demonstrate how confident the winner is or to determine the winner if the game is a draw.
- Apply phase shift gates like S or T gates before making a move. This could affect the probability amplitudes of the states, creating interference patterns in probabilities.
- Implement the
Undo
andRedo
functionalities for the game. But this is a bit complex for cases like entanglement or after collapsing. - Develop an
AI
opponent that adaptively uses quantum strategies, learning from the player's moves.