Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xtagon/snek
Battlesnake-compatible rulesets and board positions in Elixir.
https://github.com/xtagon/snek
battlesnake battlesnake-community battlesnakeio elixir elixir-lang elixir-library
Last synced: 3 months ago
JSON representation
Battlesnake-compatible rulesets and board positions in Elixir.
- Host: GitHub
- URL: https://github.com/xtagon/snek
- Owner: xtagon
- License: mit
- Created: 2020-08-15T16:17:00.000Z (over 4 years ago)
- Default Branch: edge
- Last Pushed: 2021-09-18T18:17:48.000Z (over 3 years ago)
- Last Synced: 2024-10-30T16:56:29.564Z (3 months ago)
- Topics: battlesnake, battlesnake-community, battlesnakeio, elixir, elixir-lang, elixir-library
- Language: Elixir
- Homepage:
- Size: 168 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Snek
A framework for defining Battlesnake-compatible rulesets and board positions in
Elixir.[Battlesnake][battlesnake] is an online competitive take on the classic game of
Snake. `Snek` provides some structure and tooling that developers can use
toward creating Battlesnake AIs in Elixir.This project is not affiliated with or sponsored by Battlesnake.
## Status
This is an early work in progress, and should be considered experimental,
incomplete, and unstable until v1.0.0, following [Semantic Versioning][semver].All notable changes will be recorded in the [changelog](CHANGELOG.md).
## Installation
Add `snek` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:snek, "~> 0.4.0"}
]
end
```## Documentation
Documentation can be found [here at Hex.pm][hexdocs] or generated from the
source code using `mix docs`.## Examples
The following example simulates a couple of game turns using the Standard
ruleset, for a two-player game, on a standard medium (11x11) board size.```elixir
alias Snek.Ruleset.Standard
alias Snek.Board# Two-player game
snake_ids = MapSet.new(["snek1", "snek2"])# Initialize the game
{:ok, turn0} = Standard.init(Board.Size.medium, snake_ids)# The ruleset emits `Snek.Board` states that you can analyze in various ways:
Board.empty?(turn0) # => false
Board.alive_snakes_remaining(turn0) # => 2# Apply moves for two turns
turn1 = Standard.next(turn0, %{"snek1" => :left, "snek2" => :up})
turn2 = Standard.next(turn1, %{"snek1" => :down, "snek2" => :right})# Is the game over? (See if you can figure out *why* the game isn't over!)
Standard.done?(turn2) # => false
```All rulesets implement the same callbacks, so you can perform dynamic dispatch.
In the following example, the `ruleset` variable could be set to any ruleset
module name:```elixir
ruleset = Snek.Ruleset.Solo{:ok, turn0} = ruleset.init(Board.Size.medium, snake_ids)
```## Open Invite
If you have any questions, or just wish to geek out and chat about Battlesnake
or Elixir or programming in general, feel free to reach out! I love talking
with people and sharing tips and tricks.You can reach me at [[email protected]](mailto:[email protected]), or catch me in
[Battlesnake Discord][battlesnake-discord] (username: `@xtagon`).## Development
The following Mix tasks are available to assist in development:
- `mix docs`
- `mix test`
- `mix coveralls`
- `mix credo --strict`
- `mix bench`
- `mix profile`## License
This project is released under the terms of the [MIT License](LICENSE.txt).
[battlesnake]: https://play.battlesnake.com/
[battlesnake-discord]: https://play.battlesnake.com/discord/
[semver]: https://semver.org/
[hexdocs]: https://hexdocs.pm/snek/