I am trying my hands on Reinforcement/Deep-Q learning these days. And I started with a basic game of 'Snake'. With the help of this article: https://towardsdatascience.com/how-to-teach-an-ai-to-play-games-deep-reinforcement-learning-28f9b920440a Which I successfully trained to eat food. Now I want it to eat food in specific number of steps say '20', not more, not less. How will the reward system and Policy be changed for this? I have tried many things, with little to no result. For example I tried this:
def set_reward(self, player, crash):
self.reward = 0
if crash:
self.reward = -10
return self.reward
if player.eaten:
self.reward = 20-abs(player.steps - 20)-player.penalty
if (player.steps == 10):
self.reward += 10 #-abs(player.steps - 20)
else:
player.penalty+=1
print("Penalty:",player.penalty)
Thank You. Here's is the program: https://github.com/maurock/snake-ga