An open API service indexing awesome lists of open source software.

https://github.com/goktug97/pythonsnake

A Snake Environment to Train AI Algorithms
https://github.com/goktug97/pythonsnake

artificial-intelligence evolution-strategies game genetic-algorithm python reinforcement-learning

Last synced: 4 months ago
JSON representation

A Snake Environment to Train AI Algorithms

Awesome Lists containing this project

README

          

Python Snake
==========================================

A Snake environment to train AIs.

![Playing](https://raw.githubusercontent.com/goktug97/PythonSnake/master/snakeai.gif)

## Requirements
* numpy

### Demo GUI
* cv2

## Install

```bash
git clone https://github.com/goktug97/PythonSnake
cd PythonSnake
python setup.py install --user
```

## Play

``` bash
python-snake
```

## Usage

Check [play.py](https://github.com/goktug97/PythonSnake/blob/master/play.py) for an example.

``` python
import snake
import AwesomeAIAlgorithm
import cv2

game = snake.Game()
best_ai = AwesomeAIAlgorithm.BestAI()

while not game.done:
screen = game.draw(block_size=15)
cv2.imshow('center', screen)
if cv2.waitKey(50) == 27:
break
action = best_ai.eval(game.map, game.snake.head,
game.snake.x_direction,
game.snake.y_direction,
game.apple)
game.step(action)
```