An AI-driven Snake game implementation that uses neural networks and genetic algorithms to create an autonomous snake that learns and improves its gameplay over time.
- Neural Network Control: Snake movements are controlled by a neural network that learns optimal paths
- Genetic Evolution: Implements genetic algorithms to evolve better snake behaviors across generations
- Real-time Visualization:
- Neural network architecture visualization
- Movement heatmap display
- Game state and performance metrics
- Adaptive Learning: Snake learns to avoid collisions and find efficient paths to food
- Persistence: Saves learned behaviors using IndexedDB for continuous improvement
- TypeScript
- D3.js for network visualization
- Vite as build tool
- Pako for data compression
- Node.js (v14 or higher)
- npm or yarn package manager
- Clone the repository
- Install dependencies:
npm install
- Start the development server:
npm run dev
- Open your browser and navigate to the local server address (typically http://localhost:5173)
The snake's brain is implemented as a neural network with:
- Input layer: Processes environmental data (distance to food, walls, self)
- Hidden layer: Processes complex patterns
- Output layer: Determines movement direction
The game implements a genetic algorithm that:
- Maintains a population of neural networks
- Evaluates performance based on score and survival time
- Selects best performers for breeding
- Applies mutations to explore new strategies
- Creates new generations with improved behaviors
Implements A* pathfinding algorithm with:
- Dynamic path calculation to food
- Collision avoidance with walls and self
- Efficient space utilization
npm run build
npm run preview
MIT