I’m trying to make an AI that plays Snake. I’m new to this stuff and need help picking the right neural network setup.
My game board is 10x10. I’ve got three layers of input:
- Snake body parts
- Apple location
- Snake head position
Each layer uses 1s and 0s to show where things are.
The AI needs to choose from four moves: up, down, left, or right.
What’s a good neural network setup for this? Is my input method okay? Any tips would be great!
Here’s a simple code snippet to show what I mean:
import numpy as np
board_size = 10
input_layers = 3
game_state = np.zeros((input_layers, board_size, board_size))
# Mark snake body
game_state[0, 5, 5] = 1
game_state[0, 5, 6] = 1
# Mark apple
game_state[1, 2, 8] = 1
# Mark snake head
game_state[2, 5, 6] = 1
# Output should be something like [0, 1, 0, 0] for 'move right'
Any help is appreciated!
Your input method looks solid, but you might want to consider a more efficient representation. Instead of using three separate layers, you could combine the snake body and head into one layer, saving some processing power. For the network architecture, a convolutional neural network (CNN) could work well here. Start with a few convolutional layers to extract spatial features, followed by some dense layers. For the output, use four neurons with softmax activation to get probabilities for each direction. You’ll want to experiment with different layer sizes and depths to find the sweet spot for your specific game setup. Remember to implement a reward system that encourages the snake to grow while avoiding collisions. Good luck with your project!
hav u tried using a simple feedforward network first? might be easier to start with. for input, u could flatten ur 3 layers into a single 1D array. maybe try 2-3 hidden layers with ReLU activation. output layer with 4 neurons (softmax) for directions. adjust network size based on how it performs. good luck with ur project!