Code Monkey home page Code Monkey logo

snek's Introduction

Snek

A framework for defining Battlesnake-compatible rulesets and board positions in Elixir.

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.

All notable changes will be recorded in the changelog.

Installation

Add snek to your list of dependencies in mix.exs:

def deps do
  [
    {:snek, "~> 0.4.0"}
  ]
end

Documentation

Documentation can be found here at Hex.pm 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.

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:

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], or catch me in 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.