A competitive, AI-driven snake game built using Pygame. This project features a tournament-style system where multiple bots compete in rounds to determine the ultimate winner.
- AI-controlled snakes (Strategic, Greedy, Random, Custom)
- Tournament system with multiple rounds
- Traps, food, and collision detection
- Time-based survival advantage logic
- Extensible bot interface
- Human player support (
UserBotplaceholder) - Configurable game settings
- Clone the repository:
git clone https://github.com/yourusername/snake-tournament.git
cd snake-tournament- Install dependencies:
pip install -r requirements.txtMake sure you have Python 3.8+ and pygame installed.
Run the game:
python main.py- Press
SPACEto start a new tournament or begin the next round. - Press the close button or
CTRL+Cin the terminal to quit the game.
The following AI bots are included in the game:
| Bot | Strategy Description |
|---|---|
RandomBot |
Chooses directions randomly |
GreedyBot |
Moves toward the nearest food |
StrategicBot |
Avoids traps, considers opponent position, seeks survival |
CustomBot |
Placeholder for your own custom logic |
UserBot |
Allows human input (currently not active by default) |
To change the bots used in the game, modify the following lines in main.py (or wherever SnakeGame is initialized):
self.bot1 = StrategicBot()
self.bot2 = GreedyBot()
# self.user_bot = UserBot()You can tweak gameplay settings in game_settings.py, such as:
Segment_Penaltyround_timetrap_countgrowth_per_foodColors,fonts, and more
- A match consists of multiple rounds.
- If both bots tie in win count, a tiebreaker round is triggered.
- Each round can be won by:
- Outlasting the opponent
- Scoring more points (by collecting food)
- Special logic ensures fairness with timed "survival advantage" if one bot dies first due to self-collision.
snake-tournament/
│
├── main.py # Main game logic
├── game_settings.py # Game config and constants
├── bot.py # Bot strategies
├── tournament.py # Tournament manager
├── README.md # You're reading it!
└── requirements.txt # Python dependencies
- Enable
UserBotfor human vs AI mode - Add more advanced AI strategies
- Multiplayer support
Here's what a round result might look like in the console:
=== FINAL TOURNAMENT RESULTS ===
Total Rounds: 2
Draw Rounds: 0
Crashed Rounds: 0
StrategicBot: 1 wins, Total Apples: 18
GreedyBot: 2 wins, Total Apples: 20
This project is licensed under the MIT License. Feel free to fork and modify it.
Contributions are welcome! To add your own bot:
- Open
bot.py - Implements a
decide_move(snake, food, opponent)method or other logics - Instantiate your bot in
main.py
Example:
class UserBot(Bot):
def __init__(self):
super().__init__()
self.name = "MyBot"
def decide_move(self, snake, food, opponent=None):
# Implement your custom logic here
passDeveloped with ❤️ by [🧑💻Sepehr, 🧑💻Amir, 🧑💻Mohammad]
