An advanced implementation of the classic Snake game powered by artificial intelligence. The project features both Neural Network and Q-Learning approaches for training the AI to play the game.
- Classic Snake game implementation with modern graphics
- Neural Network AI implementation using TensorFlow.js
- Q-Learning AI implementation
- Adjustable game speed
- Dark/Light theme support
- Responsive design for both desktop and mobile devices
- High score tracking
- Real-time performance metrics display
- Node.js
- Express.js
- Socket.IO
- TensorFlow.js
- HTML5 Canvas
- CSS3
Before you begin, ensure you have the following installed:
- Node.js (version 12 or higher)
- npm (comes with Node.js)
- Clone the repository:
git clone https://github.com/yourusername/ai-snake.git
cd ai-snake- Install dependencies:
npm install- Start the server:
npm start- Open your browser and navigate to:
http://localhost:3002
- The game starts with a basic snake implementation
- Use the speed slider to adjust the game speed
- Click "AI'yı Başlat" (Start AI) to begin AI training
- Click "AI'yı Durdur" (Stop AI) to stop the AI
- Toggle between light and dark themes using the theme button
- Monitor the AI's performance through the displayed metrics:
- Current Score
- Generation/Iteration Count
- Average Score
- Loss Value (Neural Network only)
server.js- Express server setup and Socket.IO configurationpublic/index.html- Main game interfacestyle.css- Game stylinggame.js- Core snake game implementationneural_network.js- Neural Network AI implementationqlearning.js- Q-Learning AI implementation
- Input Layer: 11 neurons (food direction, dangers, tail proximity, etc.)
- Hidden Layers: Multiple dense layers with dropout
- Output Layer: 3 neurons (forward, left, right)
- Uses experience replay for training
- Implements epsilon-greedy exploration strategy
- State space includes food direction and danger detection
- Actions: forward, left, right
- Implements epsilon-greedy exploration
- Uses Q-table for state-action value mapping
Feel free to submit issues and enhancement requests!
This project is open source and available under the MIT License.