What neural network structure should I use for my Snake game AI?

I’m just starting with AI and reinforcement learning. I want to build a bot that can learn how to play the Snake game but I’m stuck on picking the right network design.

My game state is represented as a 3x10x10 array. Think of it as three 10x10 grids stacked together. Each grid only has 0s and 1s. The first grid shows where the snake’s body is located. The second grid marks where the food appears. The third grid shows the snake’s head position.

I need the network to output 4 numbers that represent the four directions the snake can move (up, down, left, right).

Can anyone suggest what kind of network architecture would work best for this setup? Also, does my way of representing the game state make sense or should I change it somehow?

Skip the complex architectures. I’ve built Snake AIs before and a simple Dense network with 2 hidden layers (128 and 64 neurons) works great.

Your state representation looks good but you’re missing the snake’s current direction. Trust me - I learned this the hard way when my first bot kept trying to move backwards and dying instantly.

Add a fourth channel or append 4 extra inputs (one-hot encoded direction). That’s 300 + 4 = 304 inputs total.

For training, Double DQN beats regular DQN every time. The target network stability makes a huge difference. Also add a small penalty for each move to encourage shorter games instead of wandering around.

Reward structure matters more than network architecture here. Give +10 for food, -10 for death, and -0.1 per step. This pushes the AI to hunt food instead of just staying alive.

Start simple, get it working, then optimize. Most people overthink the network when the real challenge is getting the training loop right.

A basic feedforward neural network works great for Snake. Flatten your 3x10x10 input to 300 neurons, add 2-3 hidden layers with 128-256 neurons each, then output to 4 neurons for directions. Your state setup looks solid. Separating snake body, food, and head into different channels makes it easy for the network to tell them apart. I’d add the snake’s current direction as extra input though - stops the AI from immediately backing into itself. Start with DQN for training. It’s beginner-friendly and handles discrete actions like yours really well. This architecture has worked reliably for me on similar grid games. Set learning rate to 0.001 and tweak from there based on how stable training looks.

CNNs are definitely worth trying since you’ve got spatial grid data. A simple setup with 2-3 conv layers plus some fully connected layers should catch spatial patterns way better than flattening everything. Your state representation looks solid - keeping channels separate is smart. But I’d add velocity info or recent direction history so the network can understand movement patterns. Snake AI gets stuck in loops without that temporal context. For the output layer, use epsilon-greedy exploration during training or you’ll get trapped in local optima. Your grid size works fine for either CNNs or dense networks, but CNNs will generalize better if you scale up the board later.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.