Snake Game

Tasks:

Current Features:

Background:

Hamiltonian Cycle is a gridPath in graph theory that visits each vertex exactly once. Implementing this in the snake game, the snake visits every square on the board exactly once. This prevents the snake from ever hitting itself or the wall and will always grow the apple, no matter what random location it is generated in except when the field/canvas does not have an even number of columns and rows.

This may be easily resolved by adding one HC cycle for even columns or rows and odd columns and rows. However, this is very boring, so we will try to implement a code that will allow the snake to generate a new HC cycle every time it eats an apple and one that avoids the possibility of hitting itself in the cycle where the map does not have even sides.

Note: Due to the toggle button you may toggle the algorithms when the snake is in a position where it cannot win. Solution: Toggle only after eating an apple again. When running A* Algorithm if it fails to find a best path it will toggle to Hamiltonian Cycle to guarantee a safe path then back to A*