Skip to content

Instantly share code, notes, and snippets.

@ryan-lam
Last active December 29, 2019 01:58
Show Gist options
  • Select an option

  • Save ryan-lam/781ebf1dfcfad22d039768d3188105d2 to your computer and use it in GitHub Desktop.

Select an option

Save ryan-lam/781ebf1dfcfad22d039768d3188105d2 to your computer and use it in GitHub Desktop.
import qiskit
qc = qiskit.QuantumCircuit(3,3)
for i in range(3):
qc.h(i)
turns = 6
print("Welcome to Quantum PvP!. In this game, there are 3 qubits in a quantum circuit that start off in a superposition state. \
What you (player 1) are trying to do is to get the qubit to collapse into the \"0\" state. Your opponent (player 2) will \
trying to do the same, but they will be trying to get the qubit to collapse into the \"1\" state. \
You are both able to apply the [X], [Y], [Z], [Rx], [Ry], [Rz], [CNOT], [SWAP], and onto the circuit \
to manipulate the qubits. You each will have 3 opportunies to apply the gates before the game measures the qubits. Good luck!")
def player(turns):
if turns%2 == 0:
return 1
else:
return 2
while turns > 0:
gate = input("It is player " + str(player(turns)) + "'s turn. Which gate would you like to apply? [X], [Y], [Z], [Rx], [Ry], [Rz], [CNOT] or the [SWAP] gate? Choose your section by typing the letters within the square brackets").replace(" ", "").lower()
print(gate)
if gate == "x":
qubit = int(input("Which qubit would you like to apply the [X] gate to? Input \"1\", \"2\", or \"3\".").replace(" ","")) - 1
qc.x(qubit)
print(qc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment