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

I’m just starting out with AI and trying to build a bot that can play the Snake game. I’m stuck on picking the right network design for my data setup.

My game state is represented as a 3x10x10 array. Think of it like three separate 10x10 grids stacked on top of each other. Each grid uses just 0s and 1s. The first grid shows where the snake’s body segments are located. The second grid marks where the food item appears. The third grid indicates the snake’s head position.

I need the network to output 4 numbers that represent the possible actions - moving up, down, left, or right.

Can anyone suggest what type of network architecture would work best for this setup? Also, does my way of representing the game state make sense, or should I consider a different approach?

I’d mix both approaches - use a few conv layers to grab spatial features, then flatten and pass to dense layers. Your 3-channel setup looks good, but consider adding game context like snake length or distance to food as extra inputs. Works great in my experience.

Your state representation looks good. I’ve done something similar for a client project that needed spatial understanding.

Honestly, I’d try a simple dense network first before jumping to CNNs. With 10x10 grids, you’re only looking at 300 input features total. That’s totally manageable.

Start with 300 → 128 → 64 → 4. Use ReLU activations and throw in batch normalization between layers. I’ve seen this work surprisingly well for grid games.

Snake isn’t that spatially complex. The agent just needs to know where walls are, where food is, and not hit itself. Dense networks handle these patterns just fine.

You can always try CNNs later if you want. But dense networks train faster and they’re way easier to debug when you’re starting out. Get a working baseline first, then upgrade.

One tip from my experience - add a small penalty for getting too close to walls or the snake body. Really helps with training stability.

Been working on game AI for a while and your state representation looks solid. I’d approach this as a reinforcement learning problem instead of just tweaking the network architecture. Your 3x10x10 setup works great with DQN, which is perfect for Snake.

For the network itself, I’ve had good luck keeping it lightweight - two conv layers with 16 and 32 filters, then straight to output. Skip the massive fully connected layers. Snake decisions are mostly local anyway. You’re rarely planning more than 2-3 moves ahead, so you don’t need deep feature extraction.

Here’s where most people mess up: the reward system, not the architecture. Don’t just reward food collection - also reward survival time and efficient pathing. If you go with DQN, try prioritized experience replay. It made a huge difference in my Snake bot’s learning speed.

I’ve built similar snake AI projects, and your 3x10x10 state setup looks great. CNNs are perfect here since you’ve got spatial data. Start with 2-3 conv layers using 3x3 or 5x5 kernels to catch local patterns, then add fully connected layers for your 4 actions. The conv layers will pick up relationships between snake parts, food, and head position. Throw some dropout between the FC layers - it saved me from overfitting. Your multi-channel approach is smart too. Way better than cramming everything into one channel since the network can learn specific features for each game element.

Had this exact problem last year. Your representation looks good - don’t overthink the architecture choice. Skip the CNN vs dense debate and focus on what Snake actually needs: avoid walls/body and find food. Your three-channel setup nails this perfectly. I went with a simple 2-layer CNN (16 and 32 filters) → flatten → 128-unit dense → output. Snake patterns are local - you mostly care about what’s right around you and where the food is. Deeper networks just overcomplicate things without better results. One change I’d make: ditch pure binary inputs. Use values that show distance or direction gradients instead. This seriously helped my training converge faster. Also, heavily penalize death in your reward function - don’t just reward food collection. Trust me on this one.