A simple implementation of Deep Q-learning for playing the famous Snake game.
To train your own agent to play on a 10x10 grid:
import dqn.agent as agent
dqn_agent = agent.DQNAgent(grid_size=10)
dqn_agent.train(save_name="my_model")
At the end of the training, the model will be saved in ./dqn/trained_models/.
Note that this code uses the default configuration but you can modify any of the learning parameters of the train() function, e.g., num_steps, batch_size, learning_rate etc...
To watch a pre-trained agent playing the game:
import dqn.agent as agent
import game.snake_game as game
dqn_agent = agent.DQNAgent(grid_size=10)
dqn_agent.load_model("dqn-10x10x2")
snake_game = game.SnakeGame(grid_size=10)
snake_game.play(dqn_agent)
You can also play the game on your own using the keyboard arrows:
import game.snake_game as game
snake_game = game.SnakeGame(grid_size=10)
snake_game.play()