Skip to content

MarkZH/Genetic_Chess

Repository files navigation

Genetic Chess

An amateur attempt at breeding a chess-playing AI.

This program attempts to create a chess-playing AI by playing prospective AIs against each and letting the winners produce mutated copies. As evidence that this has a chance of working, here's a plot from a recent run of the value that the AIs place on each type of piece.

An example of the evolution of piece values

It took awhile (tens of thousands of generations), but it did figure out the correct ordering and relative value of the major pieces. Pawns have other genes measuring the influence of their positions, so their absolute value tends to be zero instead of the traditional one.

Quick build instructions

Linux

  1. Install gcc or clang
  2. Clone this repository to your computer.
  3. ./create_Makefile gcc (or clang)
  4. make release

Windows

  1. Clone this repository to your computer.
  2. Open Genetic_Chess.sln in Visual Studio and compile.

Documentation

  • make user_manual for the User Manual PDF (requires pdflatex)
    • Or compile doc/reference.tex with TexWriter or similar.
  • make code_docs for HTML source code references
  • make docs for both

Start a game

  1. Install a chess GUI (e.g., cutechess)
  2. Create a new engine with the compiled executable and with the command-line parameters -genetic genome_example.txt
    • After running a gene pool, you can replace the genome_example.txt argument with the file name and ID number of the best specimen from the gene pool.

Start a gene pool

  1. Edit gene_pool_config_example.txt to adjust the number of simultaneous games to a number less than or equal to the number of processors on your computer.
  2. <bin location>/genetic_chess -gene-pool gene_pool_config_example.txt
    • If compiling with Visual Studio, look in x86/Release or x64/Release for the compiled program.
  3. Every few hours or days, pause the gene pool with Ctrl-Z (Linux) or Ctrl-C (on Windows) and run python3 analysis/run_all_plots.py gene_pool_config_example.txt to generate plots and other data showing the evolution and behavior of the specimens.
    • This script requires python3, numpy, and matplotlib to run.