Snake-gym is a custom environment of the classic snake game using OpenAI Gym. It is meant to test different Reinforcement Learning Agents. It has a "human" mode to serve as a Single Player game.
$> pip install -r requirements.txt
How to run:
$> python3 main.py [--mode ] [--episodes ]
mode = "bot" or "human" [default = "bot"],
num_episodes = number of games to simulate [default = 30]
Rewards and Penalties:
-1000 if snake dies
+10 if snake ate food
-1 if snake moves 1 block
A sample Agent class is defined to demonstrate the Agent-Environment interaction. Average Scores of all the games played is displayed at the end. The grid dimensions are 20x20.
Snake is allowed to move in 3 directions w.r.t. its body orientation:
LEFT (left arrow key), STRAIGHT (up arrow key), RIGHT (right arrow key)
The state of the environment at any instant is modelled as a complete 20x20 grid with the following notation:
0 -> empty cell
1 -> snake head + body
2 -> food
Game terminates when the snake hits his head on the wall or tries to eat itself.
Submitted by Rhushabh Gedam (Rhushabh1)
Download packets of source code on Coders Packet