Introduction to the Snake AI Project
The Snake AI Project explores the intriguing world of artificial intelligence through the classic Snake game. The main objective of the game is simple: guide the snake to consume food continuously and grow larger until it fills the entire map with its body. Although the project was initially developed in C++, it has been translated into Python. This shift not only provides a more user-friendly graphical interface but also simplifies the integration and experimentation of algorithms.
Algorithms and Performance Metrics
The project evaluates various AI strategies using two main performance metrics:
- Average Length: This measures how long the snake grows on average, with the maximum possible length being 64.
- Average Steps: This assesses the average number of steps the snake takes during the game.
Here's a quick glance at the performance results from testing different algorithms over 1000 game episodes:
Solver | Demo (optimal) | Average Length | Average Steps |
---|---|---|---|
[Hamilton][doc-hamilton] | ![Hamilton Demo][demo-hamilton] | 63.93 | 717.83 |
[Greedy][doc-greedy] | ![Greedy Demo][demo-greedy] | 60.15 | 904.56 |
[DQN][doc-dqn] (Experimental) | ![DQN Demo][demo-dqn] | 24.44 | 131.69 |
The Algorithms:
- Hamilton Solver: Near-optimal, it fills almost the entire map efficiently.
- Greedy Solver: Focuses on immediate food but less effective in planning long-term movements.
- DQN (Deep Q-Network) Solver: An experimental approach using deep reinforcement learning, yielding moderate success.
Getting Started
To run the Snake AI Project, ensure you have Python 3.6 or higher installed, along with the Tkinter library for GUI support. Here’s a simple setup guide:
- Install the necessary dependencies:
pip install -r requirements.txt
- Launch the main program:
python run.py [-h]
- Run the unit tests to verify everything is set up correctly:
python -m pytest
Licensing
For more details about the usage and distribution rights, please refer to the LICENSE file included in the project repository.
The Snake AI Project not only challenges the players but also provides a platform for exploring the application of AI algorithms in a dynamic and engaging environment. Whether you're a beginner in AI concepts or a seasoned expert, this project offers an exciting opportunity to dive into the mechanics of AI in games.