A Python simulation model for analyzing AI strategies in Chain Duel, inspired by Chain Duel Online.
This project offers three modes for snake-like duels:
- Interactive mode with grid display:
- Play against AI (use arrow keys)
- Watch two AIs compete
- Simulation mode for batch analysis
# Create and activate virtual environment
python3 -m venv env
source env/bin/activate
# Install dependencies
pip install -r requirements.txtStart the game:
python main.py##Setup (Windows)
- Download and install Python
- In your Python prompt: cd C:[location of your file] python main.py
Start the game:
- select your game mode
- to modify the number of simulations, modify the source code files
- Player vs AI: Control green snake with arrow keys while AI controls orange
- AI vs AI: Watch two AI strategies compete in real-time
- Controls: R to restart, ESC to quit
Runs multiple games without visualization for statistical analysis. Results saved in simulations/sim_TIMESTAMP/:
results.txt: Detailed game datastats.txt: Performance metrics
- Run full batch simulation across all strategies and cases:
This generates
python run_batch_simulations.py
batch_results.csvandSTRATEGIES_AND_CASES.mdin the project root. - Analyze and visualize the results:
Outputs are saved under
python analyze_results.py
analysis_outputs/:RESULTS_SUMMARY.md: Markdown report with- Overall average win‑rate table and bar chart
- Per‑case win‑rate matrices and heatmaps
- Strategy win‑rate comparison across the 4 initial cases (table & line chart)
- PNG charts:
overall_avg_win_rate.pngheatmap_<case>.png(one per case)comparison_win_rate_cases.png(strategy vs cases)
├── main.py # Main entry point
├── src/
│ ├── core/ # Game mechanics
│ ├── strategies/ # AI implementations
│ ├── ui/ # Game interface
│ └── simulation/ # Batch simulation
- Evaluate point deduction on first food collection
- Implement competitive scoring mechanics
- Add multiplication factors based on snake length
- Implement direct path to first food (Player 1)
- Add hairpin maneuver for first food (Player 2)
- Develop minimal avoidance with food seeking
- Food-unreachable behaviors:
- Center positioning
- Board half switching
- Quadrant selection (based on food history)
MIT License - Feel free to use this code for any purpose while maintaining the license notice.
Based on the Chain Duel game: https://chainduel.net/ & https://github.com/Asi0Flammeus/chainduel_simulation/