This AI-powered snake game uses the Breadth-First Search (BFS) algorithm to navigate the snake autonomously. Learn how this project was developed by watching this YouTube video (Arabic).
- Download and install Python 3.
- Install the required modules by executing the following command in your terminal:
pip install pygame
- Run
play.py
to start the game.
settings.py
: This file houses game configurations and global variables such as width and height.snake.py
: This is where the Snake and Square classes are defined.play.py
: Contains the code required to run the game.
- The snake uses the BFS algorithm to find the shortest path (path_1) to the apple. If path_1 is not accessible, the process moves to step 4.
- A virtual snake, identical to the actual one, is created and set to follow path_1.
- Once the virtual snake reaches the apple, the path between its head and tail (path_2) is checked. If accessible, the actual snake is then directed to follow path_1.
- If either path_1 or path_2 is inaccessible, the actual snake is commanded to follow its tail.
For more details, please read the comments in the .py
files.
- Hayder Kharrufa - Initial work
This project is licensed under the MIT License - see the LICENSE.md file for more details.