AI plays snake game using BFS (Breadth-First Search) algorithm.
See how I made this project in this YouTube video (Arabic)
- Install Python 3.
- Install these modules:
pip install pygame
- Run play.py file.
- settings.py : contains game settings and global variables like width, height, etc..
- snake.py : contains Snake and Square classes.
- play.py : contains code for running the project.
- The snake will use BFS algorithm to find the shortest path between its head and the apple (let's call it path_1). If path1 is not available, then go to step 4.
- Create a virtual snake identical to the original snake and make it follow path_1.
- After the virtual snake reaches the apple, check if the path between the virtual snake's head and its tail is available (let's call it path_2), if so, then make the original snake follow path_1.
- If path_1 or path_2 are not available, make the original snake follow its tail.
For more details, read the comments in .py files.
- Hayder Kharrufa - Initial work -
This project is licensed under the MIT License - see the LICENSE.md file for details.