I'm using a DQN Algorithm to play Snake.
The input of the neural network is a stack of 4 images taken from the games 80x80.
The output is an array of 4 values, one for every direction.
The problem is that the program does not converge and I've a lot of doubts in the replay function, where I train the neural network over a batch of 32 events.
That's the snippet:
def replay(self, batch_size): minibatch = random.sample(self.memory, batch_size) for state, action, reward, next_state, done in minibatch: target = reward if not done: target = (reward + self.gamma * np.amax(self.model.predict(next_state))) target_f = self.model.predict(state) target_f[action] = target self.model.fit(state, target_f, epochs=1, verbose=0) if self.epsilon > self.epsilon_min: self.epsilon *= self.epsilon_decay`
- +1 for eating an apple
- 0 for doing a movement without dying
- -1000 for hitting a wall or the snake hitting himself