SnakeGames.jl

Several variants of snake games written in Julia
Author JuliaReinforcementLearning
Popularity
2 Stars
Updated Last
3 Years Ago
Started In
July 2020

Please see more games in GridWorlds.jl

SnakeGames

Stable Dev Build Status

This package provides some basic variants of the snake game.

Basic Usage

pkg> add SnakeGames

julia> using SnakeGames

julia> play()

Single snake and single food. The snake can move through the boundary.


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.


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.


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.

Used By Packages

No packages found.