Skip to content

About

Solving the Eight Queens problem using a Genetic Algorithm in Python.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Genetic Algorithm — Eight Queens

A Python implementation of a Genetic Algorithm for solving the classic Eight Queens problem.

📌 Overview

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.

🧬 Genetic Algorithm

A Genetic Algorithm is an evolutionary optimization technique inspired by natural selection.

The general process consists of:

  1. Initializing a population of candidate solutions
  2. Evaluating the fitness of each candidate
  3. Selecting better candidates
  4. Applying crossover
  5. Applying mutation
  6. Creating a new generation
  7. Repeating the process until a suitable solution is found

♟️ Eight Queens Problem

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.

🛠️ Technologies

  • Python 3
  • Genetic Algorithms
  • Evolutionary Computation
  • Optimization
  • Constraint Satisfaction

📂 Project Structure

Genetic_Algorithm/
│
├── 8Queen.py
└── README.md

▶️ Running the Project

Clone the repository and run the Python script:

python 8Queen.py

No external Python packages are required for the basic implementation.

🎯 Learning Objectives

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

🔮 Possible Improvements

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

👨‍💻 Author

Ali Valizadeh

Computer Engineer | Python Developer | AI & Automation Enthusiast

GitHub: AliValizadeh

📄 License

This project is provided for educational and experimental purposes.

About

Solving the Eight Queens problem using a Genetic Algorithm in Python.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages