https://github.com/juliareinforcementlearning/snakegames.jl
Several variants of snake games written in Julia
https://github.com/juliareinforcementlearning/snakegames.jl
snake
Last synced: 3 months ago
JSON representation
Several variants of snake games written in Julia
- Host: GitHub
- URL: https://github.com/juliareinforcementlearning/snakegames.jl
- Owner: JuliaReinforcementLearning
- License: mit
- Created: 2020-07-14T12:52:18.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-22T21:31:55.000Z (about 2 years ago)
- Last Synced: 2024-04-13T23:15:35.038Z (about 1 year ago)
- Topics: snake
- Language: Julia
- Homepage:
- Size: 2.73 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Please see more games in [GridWorlds.jl](https://github.com/JuliaReinforcementLearning/GridWorlds.jl)
# SnakeGames
[](https://JuliaReinforcementLearning.github.io/SnakeGames.jl/stable)
[](https://JuliaReinforcementLearning.github.io/SnakeGames.jl/dev)
[](https://travis-ci.com/JuliaReinforcementLearning/SnakeGames.jl)This package provides some basic variants of the [snake game](https://en.wikipedia.org/wiki/Snake_(video_game)).
## Basic Usage
```julia
pkg> add SnakeGamesjulia> using SnakeGames
julia> play()
```Single snake and single food. The snake can move through the boundary.

```julia
game = SnakeGame(;walls=[
CartesianIndex.(1, 1:8)...,
CartesianIndex.(8, 1:8)...,
CartesianIndex.(1:8, 1)...,
CartesianIndex.(1:8, 8)...])play(game)
```Add boundaries to the game. The game stop when the snake hits the wall.

```julia
game = SnakeGame(;n_snakes=2)play(game)
```2 snakes and 1 food. Game stop when two snake eat the same food.

A known bug is that, two snakes of length 1 can move across each other.

```julia
game = SnakeGame(;n_snakes=3, n_foods=5)play(game)
```3 snakes and 5 foods. Game stop when one snake hits another.

In fact, we can have many snakes and foods.

And even in the 3D mode. (TODO: add a picture.)
## Inner Representation
By default, a vector of `2*n_snakes+2` bits is used to represent the current state of each grid.
- The first `n_snakes` bits are used to mark which snakes' head occupy the grid.
- The following up `n_snakes` bits are used to mark which snakes' body occupy the grid.
- The last two bits are used to mark whether this grid is occupied by wall/food or not.You can access it via `game.board` and use it in your own algorithms.