Skip to content

Kacper0199/Snake-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake-Solver

Repo Language License Repo Elements Downloads


This snake game solver is represented by an undirected graph and the Hamiltonian Cycle algorithm that generates path visiting each vertex exactly once. This approach ensures that the snake will never collide and maximum score will be achieved.


1. Program Preview

2. More About the Algorithm

The application is based on the fundamental algorithm in the field of a graph theory to determine the cycle in the graph. Finding the cycle allows the solver to traverse all the vertices in the graph exactly once, hence it always gets maximum score in the game. The graph in algorithm.py script is represented by a hash table composed of vertices keywords. Each vertex corresponds to a cell in the game grid and is connected to its adjacents according to a schema presented in the picture below.

The algorithm calculates only one of several available paths. It is caused by a NP-complete problem and a polynomial time complexity to find all existing paths. In this program a recursive backtracking approach was also proposed.

3. Installation

Copy the repository by forking and then downloading it using:

git clone https://github.com/<YOUR-USERNAME>/Snake-Solver

To install requirements use:

cd Snake-Solver
pip install -r requirements.txt

Run App:

cd Snake-Solver
python3 main.py

4. Get Started

  • Randomly place snake on the board by pressing Space

  • To run solver press Enter

About

This snake game solver is represented by an undirected graph and the Hamiltonian Cycle algorithm that generates path visiting each vertex exactly once. This approach ensures that the snake will never collide and maximum score will be achieved.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages