Skip to content

N-Garai/Quantum-tower-defence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Quantum Tower Defense ๐ŸŽฎโš›๏ธ

Python Qiskit Pygame License

An educational tower defense game that brings quantum computing concepts to life using IBM's Qiskit SDK. Experience real quantum mechanics through engaging gameplay where enemies exist in superposition and collapse when measured!


๐Ÿ“– Table of Contents


๐ŸŒŸ Overview

Quantum Tower Defense is an innovative educational game that bridges quantum computing and gaming. Built with IBM Qiskit and Pygame, it transforms abstract quantum mechanics into tangible gameplay mechanics. Enemies exist in quantum superposition across multiple paths simultaneously until observed, creating unique strategic challenges based on real quantum phenomena.

Educational Purpose: Learn quantum computing concepts like superposition, entanglement, measurement, and phase shifts through interactive gameplay.

Target Audience: Students, educators, quantum computing enthusiasts, and gamers interested in science.


๐ŸŽฏ Key Features

Quantum Mechanics Implementation

  • โš›๏ธ Real Quantum Circuits: Uses actual Qiskit quantum circuits
  • ๐ŸŒŠ Superposition States: Enemies exist on multiple paths with probability amplitudes
  • ๐Ÿ“Š Wave Function Collapse: Measurement towers collapse superposition to definite states
  • ๐Ÿ”— Quantum Entanglement: Enemy pairs share quantum states and damage
  • ๐ŸŒ€ Phase Manipulation: Rotate probability distributions using quantum gates
  • ๐Ÿ“ก Quantum Teleportation: Transfer damage through entangled states

Gameplay Features

  • ๐ŸŽฎ 4 Unique Tower Types: Each represents a different quantum operation
  • ๐Ÿ‘พ 2 Enemy Types: Standard enemies and entangled enemy pairs
  • ๐Ÿ“ˆ Progressive Difficulty: 6+ waves with increasing complexity
  • ๐Ÿ’ฐ Resource Management: Balance money, lives, and quantum coherence
  • โœจ Visual Effects: Beautiful quantum operation animations
  • ๐Ÿ—‘๏ธ Tower Removal: Right-click and DELETE/BACKSPACE to remove towers (50% refund)
  • ๐Ÿ“ In-Game Tutorial: Learn as you play with helpful tooltips

๐ŸŽฎ Game Mechanics

Core Loop

  1. Enemy Spawning: Enemies spawn in quantum superposition across 4 paths
  2. Superposition Movement: Enemies progress along ALL paths simultaneously
  3. Tower Placement: Strategically place towers to measure, manipulate, or damage enemies
  4. Measurement: When measured, enemies collapse to a single path
  5. Defense: Prevent enemies from reaching the end to protect your base

Resource System

๐Ÿ’ต Money

  • Starting amount: $400
  • Earn money by defeating enemies
  • Spend on towers ($100-$250 each)
  • Get 50% refund when removing towers

โค๏ธ Lives

  • Starting lives: 20
  • Lose 1 life per enemy that reaches the end
  • Game over at 0 lives

๐ŸŒŠ Quantum Coherence

  • Starting coherence: 10.0 units
  • Maximum: 20.0 units
  • Regenerates at 0.1 units/second
  • Lost when enemies spawn in superposition
  • Required for maintaining quantum states

Path System

The game features 4 distinct paths representing the computational basis states:

  • Path 0 (|00โŸฉ): Top route
  • Path 1 (|01โŸฉ): Upper-middle route
  • Path 2 (|10โŸฉ): Lower-middle route
  • Path 3 (|11โŸฉ): Bottom route

Each enemy starts in equal superposition: |ฯˆโŸฉ = ยฝ(|00โŸฉ + |01โŸฉ + |10โŸฉ + |11โŸฉ)


๐Ÿ”ฌ Quantum Concepts Explained

1. Superposition

A quantum system existing in multiple states simultaneously. In the game, enemies appear semi-transparent on all 4 paths at once, with each path having a probability amplitude.

Quantum Circuit: Hadamard gates create equal superposition:

H gate: |0โŸฉ โ†’ (|0โŸฉ + |1โŸฉ)/โˆš2
Result: (|00โŸฉ + |01โŸฉ + |10โŸฉ + |11โŸฉ)/2

2. Measurement & Collapse

Observing a quantum system forces it into a definite state. Measurement towers collapse enemy superposition to one path based on probability distribution.

3. Quantum Entanglement

Two particles become correlated; measuring one affects the other. Entanglement towers link enemies so damage to one is shared with its partner (50% transfer).

4. Phase Shift

Rotating the phase of probability amplitudes to change probability distribution. Phase towers reduce the probability of enemies being on specific paths.

5. Quantum Teleportation

Transferring quantum states using entanglement. Teleportation towers transfer damage instantly across the map.

6. Decoherence

Quantum states degrading due to environmental interaction. Represented by the quantum coherence resource that decreases over time.


๐Ÿ“ฅ Installation

Prerequisites

  • Python: 3.9 or higher
  • pip: Package manager
  • Operating System: Windows, macOS, or Linux
  • RAM: 4GB minimum

Quick Start

# 1. Clone the repository
git clone https://github.com/N-Garai/Quantum-tower-defence.git
cd Quantum-tower-defence

# 2. Create virtual environment
python -m venv venv

# 3. Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# 4. Install dependencies
pip install -r requirements.txt

# 5. Run the game
python main.py

Dependency List

  • qiskit 1.0.0: Quantum computing framework
  • qiskit-aer 0.13.3: Quantum circuit simulator
  • pygame 2.5.2: Game development
  • numpy 1.26.0: Numerical computing
  • matplotlib 3.8.0: Visualization

๐ŸŽฎ How to Play

Starting the Game

  1. Launch the game: python main.py
  2. Main menu appears
  3. Press SPACE to start or T to toggle tutorial
  4. Game begins in wave preparation mode

Objective

Survive all waves by preventing enemies from reaching the end of paths!

  • Protect your base (20 lives)
  • Defeat enemies to earn money
  • Build towers strategically
  • Manage quantum coherence wisely

Game Flow

  1. Preparation Phase

    • Place towers before wave starts
    • Check resources (money & coherence)
  2. Wave Phase

    • Enemies spawn in superposition
    • Towers automatically engage enemies
    • Monitor progress on all paths
    • Watch for entangled pairs (purple link)
  3. Between Waves

    • Collect rewards from defeated enemies
    • Reposition towers
    • Prepare for next wave
    • Press SPACE to start next wave
  4. Victory or Defeat

    • Victory: Survive all waves with lives remaining
    • Defeat: All lives lost
    • Press R to restart

๐Ÿ—ผ Tower Types

1. ๐Ÿ“ Measurement Tower

Cost: $100 | Hotkey: 1 | Range: 150px | Damage: 20/sec

Function: Collapses enemy superposition to single path

Strategy:

  • Place near path intersections
  • Essential for dealing damage
  • Cheapest tower - good for early game
  • Use multiple towers for continuous measurement

2. ๐ŸŒ€ Phase Tower

Cost: $150 | Hotkey: 2 | Range: 120px | Damage: None (probability shift)

Function: Applies phase shift to reduce probability on specific paths

Strategy:

  • Place before measurement towers
  • Target shortest path to force enemies onto longer paths
  • Combine with measurement towers for control
  • Press numpad 0-3 to select target path

3. ๐Ÿ”— Entanglement Tower

Cost: $200 | Hotkey: 3 | Range: 100px | Damage: 15/sec

Function: Links two nearby enemies - damage is shared (50% transfer)

Strategy:

  • Place where enemies group
  • Doubles effective damage output
  • Very effective against multiple enemies
  • Entanglement persists until one dies

4. ๐Ÿ“ก Teleportation Tower

Cost: $250 | Hotkey: 4 | Range: 80px (attack) | Damage: 30/sec

Function: Instantly transfers damage across the map using quantum teleportation

Strategy:

  • Place at key choke points
  • Highest damage output
  • Most expensive but most powerful
  • Use to cover areas other towers can't reach

๐Ÿ‘พ Enemy Types

Standard Enemy

  • Health: 100 HP
  • Speed: 0.02 (moderate)
  • Reward: $10
  • Coherence Cost: 0.5/second
  • Spawn Rate: 70%

Appearance: Blue semi-transparent (superposition) / Red solid (measured)

Strategy: Use measurement towers for reliable takedown


Entangled Enemy Pair

  • Health: 100 HP each
  • Speed: 0.02 (synchronized)
  • Reward: $15 each (total $30)
  • Coherence Cost: 0.8/second
  • Spawn Rate: 30%
  • Special: Damage shared between pair (50% correlation)

Appearance: Purple link connecting entangled enemies

Strategy: Focus damage on one enemy to damage both, use entanglement towers


๐ŸŽฏ Controls

Keyboard Controls

Key Action
1-4 Select tower type (M, P, E, T)
SPACE Start next wave / Start game
ESC Pause / Resume / Exit
R Restart game (after game over)
T Toggle tutorial
Numpad 0-3 Select path for Phase Tower
DELETE/BACKSPACE Remove selected tower (50% refund)

Mouse Controls

Action Function
Left Click Place selected tower
Right Click Select tower for removal
Hover Preview tower range

โœจ Visual Effects (November 2025)

The game now includes professional visual effects for all quantum operations:

  • โœจ Measurement Effect: Green expanding circles showing wave function collapse
  • ๐Ÿ’ฅ Damage Numbers: Floating red numbers showing damage dealt
  • ๐Ÿ”„ Phase Effect: Orange rotating particles showing phase manipulation
  • ๐Ÿ”— Entanglement Effect: Purple particle links between entangled enemies
  • โšก Teleportation Effect: Cyan lightning beams showing instant attacks

๐Ÿง  Game Strategy

Early Game (Waves 1-2)

  1. Start with Measurement Towers
  2. Place 2-3 towers covering multiple paths
  3. Build up economy by defeating enemies

Mid Game (Waves 3-4)

  1. Diversify tower types
  2. Add Phase Towers before measurement points
  3. Place Entanglement Towers in dense areas

Late Game (Waves 5+)

  1. Maximum synergy between tower types
  2. Add Teleportation Towers for bosses
  3. Focus fire on high-value targets

๐Ÿ—๏ธ Technical Architecture

System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Main Game Loop (60 FPS)               โ”‚
โ”‚  Input โ†’ Update โ†’ Render                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
   โ†“           โ†“            โ†“
Quantum     Game         Rendering
Engine      Logic        System

Key Components

Quantum Engine (quantum_engine/)

  • Manages quantum circuits and state vectors
  • Handles enemy quantum states and entanglement
  • Uses Qiskit for real simulation

Game Logic (game_logic/)

  • Tower entities and attack logic
  • Enemy spawning and wave progression
  • Resource tracking

Rendering (rendering/)

  • Main graphics engine
  • UI components
  • Visual effects system

Configuration (config/)

  • Game constants and settings
  • Path definitions
  • Tower and enemy configurations

๐Ÿ“ Project Structure

quantum-tower-defense/
โ”œโ”€โ”€ main.py                      # Game entry point
โ”œโ”€โ”€ requirements.txt             # Dependencies
โ”œโ”€โ”€ README.md                    # This file
โ”‚
โ”œโ”€โ”€ config/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ game_config.py          # Constants
โ”‚
โ”œโ”€โ”€ quantum_engine/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ quantum_state.py         # Quantum management
โ”‚   โ””โ”€โ”€ enemy_superposition.py   # Enemy quantum behavior
โ”‚
โ”œโ”€โ”€ game_logic/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ tower.py                 # Tower types
โ”‚   โ”œโ”€โ”€ wave_manager.py          # Wave system
โ”‚   โ””โ”€โ”€ resource_manager.py      # Resources
โ”‚
โ”œโ”€โ”€ rendering/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ game_renderer.py         # Graphics
โ”‚   โ”œโ”€โ”€ ui.py                    # UI elements
โ”‚   โ””โ”€โ”€ effects.py               # Visual effects
โ”‚
โ””โ”€โ”€ notebooks/
    โ”œโ”€โ”€ 01-quantum-concepts.ipynb
    โ”œโ”€โ”€ 02-game-prototype.ipynb
    โ””โ”€โ”€ 03-full-demo.ipynb

๐Ÿค Contributing

We welcome contributions! Please see guidelines for:

  • Bug reports
  • Feature requests
  • Documentation improvements
  • Asset contributions
  • Quantum accuracy verification

Contribution Process

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see LICENSE file for details.


๐Ÿ™ Acknowledgments

  • IBM Qiskit Team: For the incredible quantum computing framework
  • Pygame Community: For the robust game development library
  • Quantum Computing Community: For education and research resources

๐Ÿ“ž Contact & Support

  • GitHub Issues: Report bugs or request features
  • Email: For private inquiries

Built with โค๏ธ and โš›๏ธ by quantum computing enthusiasts

Making quantum mechanics accessible through gaming!


Last Updated: November 7, 2025 Version: 1.1.0 Status: Production Ready โœ…

About

A game developed by python+qiskit on the basis of the concept of Quantum computing

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors