-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgate
More file actions
39 lines (31 loc) · 1.23 KB
/
gate
File metadata and controls
39 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
def run_quantum_game(level_target, user_moves):
qc = QuantumCircuit(2)
qc.h([0, 1]) # Start in superposition
# Apply user gates
for gate in user_moves:
if gate == 'X0': qc.x(0)
if gate == 'X1': qc.x(1)
if gate == 'CZ': qc.cz(0, 1)
# Analyze
state = Statevector.from_instruction(qc)
# Map targets to statevector indices
# Index 0=00, 1=10, 2=01, 3=11 (Qiskit ordering)
mapping = {"00": 0, "10": 1, "01": 2, "11": 3}
target_idx = mapping[level_target]
amplitude = state.data[target_idx]
print(f"\n--- MISSION: Target Room {level_target} ---")
# Logic: For a successful Oracle, the target's amplitude must be NEGATIVE
if amplitude.real < 0:
print(f"✅ SUCCESS: Room {level_target} is marked with a negative phase!")
return True
else:
print(f"❌ FAILED: Room {level_target} is still positive. The Oracle didn't fire.")
return False
# --- PLAYING THE GAME ---
# Level 1: Target 11 (User should only use CZ)
run_quantum_game("11", ["CZ"])
# Level 2: Target 01 (User must use X1 and CZ)
run_quantum_game("01", ["X1", "CZ"])
print(qc.draw(output='text'))