A Python implementation of a Genetic Algorithm for solving the classic Eight Queens problem.
The Eight Queens problem is a classic constraint satisfaction and optimization problem in which eight queens must be placed on an 8×8 chessboard so that no two queens can attack each other.
This project demonstrates how a Genetic Algorithm can be applied to find valid solutions to the problem.
A Genetic Algorithm is an evolutionary optimization technique inspired by natural selection.
The general process consists of:
- Initializing a population of candidate solutions
- Evaluating the fitness of each candidate
- Selecting better candidates
- Applying crossover
- Applying mutation
- Creating a new generation
- Repeating the process until a suitable solution is found
A valid solution must satisfy the following constraints:
- No two queens can be in the same row
- No two queens can be in the same column
- No two queens can share a diagonal
The Genetic Algorithm searches through possible board configurations and evolves the population toward valid solutions.
- Python 3
- Genetic Algorithms
- Evolutionary Computation
- Optimization
- Constraint Satisfaction
Genetic_Algorithm/
│
├── 8Queen.py
└── README.md
Clone the repository and run the Python script:
python 8Queen.pyNo external Python packages are required for the basic implementation.
This project provides a practical introduction to:
- Genetic Algorithms
- Population-based optimization
- Fitness functions
- Selection
- Crossover
- Mutation
- Evolutionary search
- Solving constraint-based problems with AI techniques
Future versions could include:
- Support for the general N-Queens problem
- Configurable population size
- Configurable mutation and crossover rates
- Visualization of the chessboard
- Fitness and generation statistics
- Comparison with other search algorithms
- A graphical user interface
Ali Valizadeh
Computer Engineer | Python Developer | AI & Automation Enthusiast
GitHub: AliValizadeh
This project is provided for educational and experimental purposes.