Skip to content

Dpbm/snake-ai

Repository files navigation

Snake game genetic algorithm

Build-Test workflow (cmake)

🚧In Progress🚧

The idea for this project came as a joint between my urge to learn C++ and to implement a AI from scratch.
So, actually, this project is a big lab for me, the main goal is to learn things like:

  • c++
  • cmake/make
  • ctest
  • AI algorithms
  • docker
  • SDL2

Bellow there're some youtube videos that have inspired me to create this project:

Artificial Intelligence in Google's Dinosaur (English Sub) Rede Neural aprendendo a jogar o jogo da cobrinha (SNAKE) MarI/O - Machine Learning for Video Games

Technologies

Here are listed the technologies used for this project:

Dev usage

to build the and run the project you must have a linux distro and the following tools and libraries installed:

with all that seted up, clone the project, go to thedirectory and run the compilation script as:

git clone https://github.com/Dpbm/genetic-algorithm
cd ./genetic-algorithm
chmod +x ./compile.sh ./clean.sh
./clean.sh && ./compile.sh main.cpp

then, to run the project type:

./build/ga.out

and to run the tests:

cd build
ctest

Project Structure

The project implements all from scratch, and the sub-libraries are organized in the following structure:

  1. game: This folder contains all the implementation of the snake game itself, SDL abstractions, etc.

  2. genetic: The genetic algorithm utils, like genes and chromossomes code.

  3. matrix: The sub-library to handle matrices in a simple way.

  4. helpers: Some uility functions, like random.

  5. machine: Parts to build a Neural Network.

Then all this is embedded into the main.cpp file, to build the project altogether.