This project implements a solver for the classic 8 Queens puzzle, using a backtracking algorithm to place eight queens on a chessboard so that none of them can attack each other.
Unlike standard versions of the puzzle, this implementation allows the user to:
- Specify the initial position of one queen
- Automatically compute a valid arrangement for the remaining seven
- Visualize the board in an ANSI-colored console output
The solver is lightweight, uses pure Python, and runs entirely in the terminal.
- User-defined starting position: Place the first queen anywhere on the board (e.g., A1, H8).
- Backtracking algorithm: Automatically computes a valid arrangement for the remaining queens.
- ANSI-colored console output: Clear and easy-to-read board visualization.
- Lightweight Python implementation: No external libraries required.
- Interactive input: Simple, terminal-based interface for specifying positions.
- Python 3.x (Version 3.6 or higher recommended)
- Terminal that supports ANSI colors
No additional libraries are needed.
- Clone the repository:
git clone https://github.com/lukatinarelli/8-Queens-Backtracking.git
cd 8-Queens-Backtracking- (Optional) Make sure Python 3 is in your PATH.
Run the main script and follow the prompts:
python main.py-
Enter the initial position of the first queen (e.g., A1, H8).
-
The program will automatically compute a valid solution and display the board with colored output.
Enter the initial position of the first queen (e.g., A1):
Solution found:
A B C D E F G H
+----------------+
1 |♛ - - - - - - - |
2 |- - - - - ♛ - - |
3 |- - - - - - - ♛ |
4 |- ♛ - - - - - - |
5 |- - - ♛ - - - - |
6 |- - - - - - ♛ - |
7 |- - ♛ - - - - - |
8 |- - - - ♛ - - - |
+----------------+This project is licensed under the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication.
You can freely:
- Copy, modify, and distribute the code
- Use it for any purpose, including commercial use
- No attribution required (although credit is appreciated)
This project is released into the public domain for educational and personal use.