-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame1.py
More file actions
65 lines (52 loc) · 2.32 KB
/
game1.py
File metadata and controls
65 lines (52 loc) · 2.32 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
from quantum_engine import run_quantum_level
def display_radar(probs):
"""Visualizes the 'brightness' of each room in the maze."""
print("\n--- 🛰️ QUANTUM RADAR (Probability Map) ---")
# Sort for consistent reading (00, 01, 10, 11...)
for state in sorted(probs.keys()):
# Correcting for Qiskit's Little Endian for the user
user_friendly_state = state[::-1]
percentage = probs[state] * 100
bar = "█" * int(percentage / 2) # 1 block per 2%
print(f"Room {user_friendly_state}: {percentage:5.1f}% | {bar}")
print("------------------------------------------\n")
import random
def get_random_level():
# Randomly choose between 2 or 3 qubits
qubits = random.choice([2, 3])
# Generate a random target room (e.g., 0 to 3 for 2-qubits)
target_int = random.randint(0, (2**qubits) - 1)
# Format as binary string with leading zeros
target_str = format(target_int, f'0{qubits}b')
return qubits, target_str
def start_interactive_session():
qubits, target = get_random_level()
current_moves = []
print(f"🎲 RANDOM LEVEL GENERATED")
print(f"🚀 MISSION: Find Room {target} using {qubits} Qubits")
print(f"Tools: {'CZ (2-qubit)' if qubits == 2 else 'CCZ (3-qubit)'} + X-gates")
print("ENTER GATE: 'X0', 'X1', 'CZ', 'CCZ', 'CLEAR', 'RUN', 'EXIT'")
while True:
action = input(f"Current Sequence {current_moves} > ").strip().upper()
if action == 'EXIT':
break
elif action == 'CLEAR':
current_moves = []
os.system('cls' if os.name == 'nt' else 'clear')
print(f"Mission Reset. Target: {target}")
continue
elif action == 'RUN':
win_prob, all_probs = run_quantum_level(qubits, target, current_moves)
display_radar(all_probs)
if win_prob > 0.9:
print(f"✨ SUCCESS! You've amplified Room {target} to {win_prob:.1%}")
print("You found the exit. Level Complete!")
break
else:
print(f"⚠️ SIGNAL WEAK ({win_prob:.1%}). The target is still hidden.")
else:
# Add the gate to the sequence
current_moves.append(action)
if __name__ == "__main__":
start_interactive_session()