Link to GitHub

What is a Battlesnake?

Generally

A Battlesnake is a bot that competes against other Battlesnakes in a snake-like game on play.battlesnake.com.

In-depth

A BattleSnake is an http-Server with the endpoints /start, /move and /end. The BattleSnake Servers send a new request each turn, containing all the necessary information.

Example Response

{
    "move": "up",
    "shout": "WHY ARE WE SHOUTING?"
}

Tactic

Esproso is trying to survive as long as possible, and not really caring about other snakes as long as they stay out of their way. To achieve this, Esproso first looks if there is some obstacle right next to him, and sorts the given moves out. Afterwards, it looks for food nearby and calculates the lowest distance right before heading for it.

What I learned

When I started the project, the Golang programming language was still pretty new for me, so I learned many fundamental things like http-servers or parsing JSON objects to structs.

Parsing JSON to a struct

JSON:

{
    "id": "game-00fe20da-94ad-11ea-bb37",
    "ruleset": {
        "name": "standard",
        "version": "v.1.2.3"
    },
    "timeout": 500
}

Go struct:

type Game struct {
	Id      string  `json:"id"`
	Ruleset Ruleset `json:"ruleset"`
	Timeout int     `json:"timeout"`
}
type Ruleset struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

And after that, the hardest part is already done.

Technical specifications