{"id":14977259,"url":"https://github.com/sintefmath/quantumpoker","last_synced_at":"2025-10-28T03:30:46.400Z","repository":{"id":45431315,"uuid":"199462509","full_name":"sintefmath/QuantumPoker","owner":"sintefmath","description":"Quantum Poker – a serious pedagogical tool to learn quantum computing that is fun to play","archived":false,"fork":false,"pushed_at":"2021-12-14T12:31:42.000Z","size":1813,"stargazers_count":27,"open_issues_count":0,"forks_count":12,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-02-01T10:41:34.343Z","etag":null,"topics":["game","ipynb","jupyter-notebook","python","qiskit","quantum-computing","quantum-poker"],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sintefmath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-29T13:52:40.000Z","updated_at":"2025-01-30T20:24:31.000Z","dependencies_parsed_at":"2022-08-30T08:40:51.397Z","dependency_job_id":null,"html_url":"https://github.com/sintefmath/QuantumPoker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sintefmath%2FQuantumPoker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sintefmath%2FQuantumPoker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sintefmath%2FQuantumPoker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sintefmath%2FQuantumPoker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sintefmath","download_url":"https://codeload.github.com/sintefmath/QuantumPoker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238590593,"owners_count":19497351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game","ipynb","jupyter-notebook","python","qiskit","quantum-computing","quantum-poker"],"created_at":"2024-09-24T13:55:22.293Z","updated_at":"2025-10-28T03:30:45.895Z","avatar_url":"https://github.com/sintefmath.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Quantum Poker\nThis repository contains all the necessary components to learn and play quantum poker. The game works in the same way as Texas hold 'em poker with the main difference being that the community cards are replaced by qubits and the player cards are replaced by quantum logic gates. Don't fear if you don't understand the jargon, you can play the game anyway.\nThis implementation is a proof-of-concept, but it is fully possible to create apps for mobile phones or tablets.\nWe hope that you will enjoy the game and get curious to look \"under the hood\" and learn quantum computing!\n\n![Quantum Poker](quantumpoker.jpg)\n\n## Basic Rules to get started\nIn order to play the basic version of this game, one does not have to learn any quantum physics, or have a rigorous understanding of poker rules.  Even if this game involves only rudimentary essentials of quantum computing, people that are new to the field will find that it takes some time to get used to the rule set. Just as with any other game, one has to learn the rules of the game, which are described in the following.\n\nAt the start of every round of quantum poker, each player is given a randomized set of personal cards drawn from a deck of available cards. These personal cards can be viewed by pressing the button marked with \"View Hand\", and are shown in the leftmost coloumn. The rightmost coloumn shows the original deck of cards. These cards are not to be used until later in the game, and their use will be explained shortly.\n\nBefore any more information is revealed to the players, a round of betting takes place. Each player has a set amount of money at the start of the game, which switches hands as the game progresses. In each round of betting one needs to at least match the current highest bet to continue playing, but you could also raise the bet by putting more money on the table. This is done by either hitting the \"Check\"/\"Call\" button to match the bet, or entering an amount to raise the bet in the \"Bet:\" box and hitting enter. You can also fold and forfeit all the money you have betted so far in this round by hitting the \"Fold\" button. Note that two of the players automatically start with some money on the table, called blinds.\n\nThree community cards are then revealed on the table. These cards have labels |0\u003e, |1\u003e, |-\u003e, or |+\u003e as well as some probabilities. The P(1)-probability determines the chance that the card gets the value 1 at the end of the round. The goal for each player is to get as many 1's as possible at the end of the round. _Later_ in the game, the players will be able to apply their personal cards to these cards to change them. The community cards on the table can change their labels in a given way. For example the personal card X changes |0\u003e to |1\u003e, and H changes |-\u003e to |1\u003e. For a full list of transformations, see the table at the end of this file. If two community cards are marked with \"Pair A\", they influence each other. This can be undone by playing the CX card.\n\nAfter the first three cards have been revealed, a second round of betting takes place, before another card is revealed. Then a third round of betting takes place, before the fifth and final card is revealed. Finally, a last round of betting takes place. After all players have finished betting, the players take turns applying their personal cards to the community cards, by first clicking on the personal card and the on the desired card. To apply the CX card the player needs to click on two qubits. Note that each player has their own cards, but that their initial values are shared by all players. After a player has used all their personal cards she wants to, she presses the \"End\" button to end her turn. Once all players are finished, each player's cards are giving either the value 0 or the value 1 based on the P(1)-probability shown on the card. The player(s) whose cards give the most 1's then wins the round, and takes all the money on the table. \n\nIf a player has no money left on the table, he is out of the game, and the winner is the last person to have any money left.\n\n## How to get started\nThe game requires the Qiskit package for Python to be able to run. For help installing Qiskit please see [qiskit.org](https://qiskit.org/documentation/install.html). In the Jupyter Notebok file [runPokerJN.ipynb](Python/runPokerJN.ipynb) an example game along with instructions on how to play the game is included. To play the game, either open the file [runInteractivePokerJN.ipynb](Python/runInteractivePokerJN.ipynb) through Jupyter Notebook (in a Qiskit environment) or run the file [runPoker.py](Python/runPoker.py) locally. Running the game in Jupyter Notebook is notably slower than running the proper Python file.\n\nYou can also find more info here [https://arxiv.org/abs/1908.00044](https://arxiv.org/abs/1908.00044).\n\n## Detailed description the game\nNote that this section assumes rudementary knowledge of how to play the game. We advise trying a couple of rounds before reading this section.\n\nThe basic entity of a quantum computer is called a quantum bit or qubit. While a classical bit can be either 0 or 1, a qubit can also exist in a combination of both 0 and 1. This is called a \"superposition\". The \"value\" of a qubit is called a qubit state, and qubit states are often written in bra-ket notation, i.e. a qubit which has the value 1 would be written as being in the state |1\u003e. An example of states that are in a superposition is the states denoted by |+\u003e = |0\u003e + |1\u003e and |-\u003e = |0\u003e - |1\u003e.\n\nIn order to obtain information on the state of qubits, they have to be measured. A measurement will collapse the state to a classical bit and return either 0 or 1.\n\nWhen measuring a qubit in state |0\u003e one will get the classical state 0 with 100% probability, and for |1\u003e one will get 1 with 100% probability. When one measures a qubit in state |+\u003e or |-\u003e however, one will either get the classical value 0 or the value 1 with equal probability for each, i.e. 50% each.\n\nAt the start of the game, a set of 5 qubits is created, where each qubit is in a randomized state. Each player is then given a copy of this set, so that all players have an identical set of 5 qubits. The goal of the game is then to change the state of your own qubits, so that as many as possible of the qubits collapse to 1 upon being measured. Remember that a qubit in state |1\u003e has a 100% chance to collapse to 1, while a qubit in state |0\u003e has a 0% to collapse to 1. Note that the states of the qubits in the set are gradually revealed to the players between each round of betting.\n\nThis brings us to next important topic, how to change the state of the qubits. This can be achieved by applying a \"gate\" to one or more qubits. In this game there a total of 4 gates. \n\nThe first gate is the X gate which changes |1\u003e to |0\u003e and |0\u003e to |1\u003e, but does nothing to |+\u003e and |-\u003e (The interested reader can check this against the definition of |+\u003e and |-\u003e. Note that the phase is of no interested, i.e. -|-\u003e=|-\u003e). We write this as X|0\u003e=|1\u003e and X|1\u003e=|0\u003e.\n\nWe also have the Z gate which does nothing to the states |0\u003e and |1\u003e, but interchanges |+\u003e and |-\u003e, i.e. Z|+\u003e=|-\u003e and Z|-\u003e=|+\u003e, and the H gate which interchanges |0\u003e and |+\u003e, and |1\u003e and |-\u003e. For a full breakdown see the table below.\n\nEach player is dealt three random gates at the start of the game, which need not be the same as for any other player. When betting ends, each player uses his/her gates to change their qubits, to maximize the chance of measuring 1 for each qubit. The winner of the round is then the player with the most measured 1 between the 5 qubits. \n\nAnother important effect in quantum computing is called entanglement. By this is meant that the measured value of two or more qubits is dependent on one another. For example both qubits might have a 50% chance to be measured to either 1 or to 0, but they will always be measured to the _same_ value. However, there is no way to know which value they will collapse to until one actually performs a measurment on at least one of the qubits. \n\nTwo-qubit states are written as |q\u003csub\u003e1\u003c/sub\u003eq\u003csub\u003e2\u003c/sub\u003e\u003e, where |q\u003csub\u003e1\u003c/sub\u003e\u003e is the state of the first qubit, and |q\u003csub\u003e2\u003c/sub\u003e\u003e is the state of the second. For example the state |00\u003e means both the first and second qubit is in the state |0\u003e. The entangled state described in the previous paragraph could be written as |00\u003e + |11\u003e or |00\u003e - |11\u003e. Both states look identical if you try to measure them directly, but will behave differently when you start applying gates. One could also have the entangled states |01\u003e + |10\u003e or |01\u003e - |10\u003e, in this case the two qubits will always be measured to different values, but again there is an equal probability for the two possibilities.\n\nThe last gate implemented in this game is the controlled NOT (CX) gate. This applies an X gate to the second qubit if the first qubit is in the state |1\u003e, and does nothing when the first qubit is in the state |0\u003e. For example the state |00\u003e is unchanged upon apllying a CX gate as the first qubit is int the state |0\u003e, but the state |10\u003e changes to the state |11\u003e. See the table below for a full overview of different possibilities when applying a CX gate.\n\nThe last thing is to note that all gates used here are their own inverse, i.e. applying a gate twice to a state will give the initial state again. However this is not the case for all possible gates.\n\n## Table for effects of the different gates\n\n#### Not gate X \u003cbr /\u003e\nX|0\u003e = |1\u003e \u003cbr /\u003e\nX|1\u003e = |0\u003e \u003cbr /\u003e\nX|+\u003e = |+\u003e \u003cbr /\u003e\nX|-\u003e = |-\u003e \u003cbr /\u003e\n\n#### Hadamard gate H \u003cbr /\u003e\nH|0\u003e = |+\u003e \u003cbr /\u003e\nH|1\u003e = |-\u003e \u003cbr /\u003e\nH|+\u003e = |0\u003e \u003cbr /\u003e\nH|-\u003e = |1\u003e \u003cbr /\u003e\n\n#### Phase flip gate Z \u003cbr /\u003e\nZ|0\u003e = |0\u003e \u003cbr /\u003e\nZ|1\u003e = |1\u003e \u003cbr /\u003e\nZ|+\u003e = |-\u003e \u003cbr /\u003e\nZ|-\u003e = |+\u003e \u003cbr /\u003e\n\n#### Controlled Not gate CX\u003cbr /\u003e\nCX|00\u003e = |00\u003e \u003cbr /\u003e\nCX|01\u003e = |01\u003e \u003cbr /\u003e\nCX|10\u003e = |11\u003e \u003cbr /\u003e\nCX|11\u003e = |10\u003e \u003cbr /\u003e\n\nCX|+0\u003e = |00\u003e + |11\u003e \u003cbr /\u003e\nCX|+1\u003e = |01\u003e + |10\u003e \u003cbr /\u003e\nCX|-0\u003e = |00\u003e - |11\u003e \u003cbr /\u003e\nCX|-1\u003e = |01\u003e - |10\u003e \u003cbr /\u003e\n\nCX|++\u003e = |++\u003e \u003cbr /\u003e\nCX|+-\u003e = |--\u003e \u003cbr /\u003e\nCX|-+\u003e = |-+\u003e \u003cbr /\u003e\nCX|--\u003e = |+-\u003e \u003cbr /\u003e\n\nCX|0+\u003e = |0+\u003e \u003cbr /\u003e\nCX|0-\u003e = |0-\u003e \u003cbr /\u003e\nCX|1+\u003e = |1+\u003e \u003cbr /\u003e\nCX|1-\u003e = |1-\u003e \u003cbr /\u003e\n\nA related game (by name) has been proposed here https://github.com/danielbultrini/Quantum-Hold-em-.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsintefmath%2Fquantumpoker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsintefmath%2Fquantumpoker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsintefmath%2Fquantumpoker/lists"}