Skip to content

lychanl/Gymnasium_Snake_Game

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake game for Farama Gymnasium

This project is based on Snake game for OpenAI Gym by Ming Yu.

Additional changes include:

  • changing observations to 2D image data
  • fixing display settings code
  • changing default parameters, including rewards, board size, and colors palette

Snake game for OpenAI Gym

Python versions PyPI License

screenshot

Quick Start

import gym_snake_game
import gymnasium

# both work
env = gymnasium.make('Snake-v0', render_mode='human')
env = gym_snake_game.make('Snake-v0', render_mode='human')
env.reset()

# for human playing
env.play()

# for ai playing
while True:
    obs, reward, done, truncated, info = env.step(env.action_space.sample())
    if done:
        break
env.close()

Available Options

import gym_snake_game

options = {
    'fps': 60,
    'max_step': 500,
    'init_length': 4,
    'food_reward': 2.0,
    'dist_reward': None,
    'living_bonus': 0.0,
    'death_penalty': -1.0,
    'width': 40,
    'height': 40,
    'block_size': 20,
    'background_color': (255, 169, 89),
    'food_color': (255, 90, 90),
    'head_color': (197, 90, 255),
    'body_color': (89, 172, 255),
}

env = gym_snake_game.make('Snake-v0', render_mode='human', **options)

Requirements

  • Python >= 3.0
  • Numpy >= 1.23.2
  • Pygame >= 2.1.3
  • Gymnasium >= 0.29.0

About

Snake game for Gymnasium

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%