We will extend the classical game by introducing quantum superposition, creating a new version called Photonic Ship.
💾 Save your classical game code—you’ll need it for reference later.
🚀 You’ll build your Photonic Ship step by step through eight tasks.
🎮 Each task includes a playable version in your browser to test your progress.
• Double the height and draw a line in the middle.
• Now, we have two screens: The upper (lower) screen will represent state |0> (|1>).
pygame.draw.line(screen, (R, G, B), (x1, y1), (x2, y2))
• When pressing key "X", our ship should switch its screen (in the same position).
• When in the upper screen, the state of our ship is "|0>".
• When in the lower screen, the state of our ship is "|1>".
• Make sure that our ship cannot cross the middle line.
state, and update it whenever the state is changed.
ship.rect.top
ship.rect.bottom
• Display the state information on the top-right corner.
• Apply Hadamard when pressing key "H".
• If in state |0> or |1>, the new state is |+> or |->, respectively.
• When entering |+> or |->, create a copy of ship and place it on the other screen.
• When in |+> or |->, our photonic ship is in superposition. We call it "quantum mode".
• When in quantum mode, make sure that the ships do not move.
• When in |+> or |-> and press "H", the new state is |0> or |1>, respectively. The mode is "classic".
twinship for the second ship. Check the code for creating the first ship.
state before updating the ship position.
• Make sure that the state info is displayed correctly on the top-right corner.
• When in state |+> or |->, the user can move only the enemies up and down.
• When pressing arrow keys "UP" or "DOWN", move every enemy accordingly.
• Enemies can cross the middle line, and when dropping from the top (resp., bottom), they appear again from the bottom (resp., top).
• Enemies should still move automatically to the left.
enemy.rect.top for its vertical (y) position. Check the code for updating the enemy.
• When in a superposition (|+> or |->), what happens if one of the ships is hit by an enemy?
• We measure our system, and our ship collopses into the up (down) screen if |0> (|1>) is observed.
• Implement this measurement and update the game accordingly.
• After measurement, decide if the ship is hit (destroyed) or survived.
• Display an informative message about the measurement outcome and the status of ship.
ship and twinship.
twinship, but then ship should appear in the correct screen.
state to determine the correct screen for ship.
ship in the same frame after collapsing and placing the correct screen.
• When in a superposition (|+> or |->), make sure that pressing X does not change the state and so the game.
• When in (|0> or |1>), pressing Z does not change the state and so the game.
• But, when in a superposition (|+> or |->), pressing Z should switch |+> to |-> and vice versa.
• Let the system applies the quantum gates (X, H, Z) randomly..
• For example, in each frame, pick a random integer between 0 and 300.
• If it is 100 or 200, applies X.
• If it is 50 or 250, applies Z.
• If it is 150, applies H.
• Apply X only in the classic mode, and Apply Z only in the quantum mode.
• Play with the randomization parameters to make it more comfortable for yourself.