Skip to content

About

Visualize the classic N-Queens puzzle ๐Ÿ‘‘ in real time using AI search algorithms โ€” Hill Climbing, Simulated Annealing, and Local Beam Search. Built with Python, Pygame, and NumPy, it beautifully animates how AI solves complex constraint problems step by step.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ‘‘ N-Queens Visualizer AI

Python pygame NumPy License-MIT Contributions

Visualize the classic N-Queens problem using AI search algorithms (Hill Climbing, Simulated Annealing, Local Beam Search) in real time with Pygame.


๐ŸŽฎ Features & Highlights

  • ๐Ÿ‘‘ N-Queens Problem: Place one queen per row/column with zero conflicts.

  • ๐Ÿ” Search Algorithms:

    • Hill Climbing with random restarts
    • Simulated Annealing with customizable temperature schedule
    • Local Beam Search with user-defined beam width
  • โฑ๏ธ Performance Metrics: Iterations, restarts, and solve time printed in console.

  • ๐ŸŽจ Graphical Board: Pygame-based animation of algorithm progress.

  • โš™๏ธ Configurable: Board size, algorithm parameters, timer interval.


๐Ÿ› ๏ธ Tech Stack

  • Language: Python 3.7+
  • Graphics: Pygame
  • Computation: NumPy

๐Ÿ“ฅ Installation & Setup

  1. Clone the repository

    git clone https://github.com/asadsandhu/n-queens-ai.git
    cd n-queens-visualizer
  2. Create & activate virtual environment (recommended)

    python3 -m venv venv
    source venv/bin/activate    # macOS/Linux
    venv\\Scripts\\activate   # Windows
  3. Install dependencies

    pip install -r requirements.txt

๐ŸŽฎ Running the Visualizer

python n_queens_visualizer.py
  1. Select Algorithm: Uncomment your choice in main():

    # hill_climbing(initial_board)
    simulated_annealing(initial_board, initial_temp=100.0, cooling_rate=0.95)
    # local_beam_search(k, initial_states)
  2. Adjust Parameters: Modify BOARD_SIZE, initial_temp, cooling_rate, or beam width k at top of script.

  3. Watch: The board updates every 500ms showing queen placements and conflict counts.


โš™๏ธ Configuration & Customization

  • BOARD_SIZE: Change number of queens/rows (modify related constants).

  • Timer Interval: Adjust pygame.time.set_timer(pygame.USEREVENT, interval_ms) for speed.

  • Algorithm Params:

    • initial_temp, cooling_rate for simulated annealing
    • k, initial_states count for local beam search

๐Ÿ“‚ Project Structure

n-queens-visualizer/
โ”œโ”€โ”€ README.md               # Project overview & instructions
โ”œโ”€โ”€ n_queens_visualizer.py  # Main visualization & AI logic
โ”œโ”€โ”€ queen.png               # Queen sprite image
โ”œโ”€โ”€ requirements.txt        # pygame, numpy
โ”œโ”€โ”€ .gitignore              # __pycache__, venv/
โ””โ”€โ”€ assets/
    โ””โ”€โ”€ (optional) GIFs/screenshots

๐Ÿค Contributing

  1. โญ Star the repo
  2. ๐Ÿด Fork
  3. ๐Ÿ’ก Create a feature branch
  4. ๐Ÿš€ Commit & push
  5. ๐Ÿ”ƒ Open a Pull Request

Please follow PEP 8 style and include examples/tests for new algorithms.


๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for details.

About

Visualize the classic N-Queens puzzle ๐Ÿ‘‘ in real time using AI search algorithms โ€” Hill Climbing, Simulated Annealing, and Local Beam Search. Built with Python, Pygame, and NumPy, it beautifully animates how AI solves complex constraint problems step by step.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages