N-Queens genetic algorithm solution with convergence chart

N-Queens Genetic Algorithm

Updated Nov 2025

PythonGenetic Algorithms

This project explores the N-Queens puzzle through a compact genetic algorithm. It is intentionally small and transparent, making it easy to inspect how population size, mutation behavior, and iteration caps affect convergence.

Tournament selection + single-point crossover

Mutation schedule that scales with board size

CLI/.env configurable experiments

What I built

  • Single-file genetic algorithm implementation with tournament selection and crossover
  • Collision-based fitness function for scoring candidate boards
  • CLI and .env configuration for quick experimentation

How it works

  1. 1Initialize a population of candidate boards
  2. 2Score conflicts and select parents via tournaments
  3. 3Apply crossover and mutation across generations
  4. 4Stop when a zero-collision solution is found or iteration cap is hit

Results

  • Good compact reference implementation for an evolutionary search workflow

Next steps

  • Add seeded benchmarking and clearer example outputs
  • Try alternate encodings or hybrid local-search ideas