/snake-gym

snake-gym is implementation of the classic game snake that is made as an OpenAI gym environment

Primary LanguagePythonMIT LicenseMIT

snake-gym

Description

snake-gym is implementation of the classic game snake that is made as an OpenAI gym environment

Dependencies

  • gym
  • numpy
  • torch

Installation

  1. Clone repository: $ git clone https://github.com/Platun0v/snake-gym.git
  2. cd into snake-gym and run: pip install -r requirements.txt

Using ready-made programs

Test network

To see pretrained snake run: python test.py

Parameters

  • load_path - path to neural network
  • render - render process
  • times - how many times to run
  • seed - seed
  • blocks - number of blocks on square grid
  • block_size - the size of block in pixels

Train network

To train snake run: python train.py

Parameters

  • save_path - path to save neural network
  • render - render process
  • episodes - how many times to run
  • seed - seed
  • blocks - number of blocks on square grid
  • block_size - the size of block in pixels

Using enviroment

import gym
import gym_snake

env = gym.make('Snake-v0')

for i in range(100):
    env.reset()
    for t in range(1000):
        env.render()
        state, reward, done, info = env.step(env.action_space.sample())
        if done:
            print('episode {} finished after {} timesteps'.format(i, t))
            break

https://habr.com/ru/post/465477/