This is a simple game of Snake with an AI component written in C++ using the SFML library. The AI component uses a BFS algorithm to find the shortest path to the apple and then checks if this path is safe. If the path is safe after eating the apple, the AI will take this path. Otherwise, it will take any available safe move.
- CMake version 3.24 or newer
- SFML 2.5 library with the graphics and audio components
- Clone the repository to your local machine.
- Install CMake and SFML on your machine if they are not already installed. You can download CMake from cmake.org and SFML from sfml-dev.org.
- Open a terminal and navigate to the project folder.
- Run the command
cmake build ./
to generate the build files. - Run the command
make
to build the executable. - Run the executable with the command
./Snake_AI
.
When you run the executable, the game will start automatically. The AI component will automatically navigate the snake towards the apple and try to get the highest score possible.
main.cpp
: The main entry point of the program.Snake.cpp
andSnake.h
: The implementation and header files for the Snake class, which represents the snake in the game.Env.h
: The header file for the Environment class, which manages the game environment.Apple.cpp
andApple.h
: The implementation and header files for the Apple class, which represents the food that the snake eats.DrawManager.cpp
andDrawManager.h
: The implementation and header files for the DrawManager class, which manages the drawing of the game objects.PathFinder.cpp
andPathFinder.h
: The implementation and header files for the PathFinder class, which implements the BFS algorithm used by the AI to find the shortest path to the apple.
This Snake AI game provides an entertaining way to experience the power of AI in action.The code is well-structured and easy to read, making it a good starting point for anyone interested in learning about game programming or AI. Give it a try and see how it work.