Skip to content

Instantly share code, notes, and snippets.

@joram
Last active March 16, 2018 18:49
Show Gist options
  • Save joram/bc02b97805f5b2fde151d74c34a4c434 to your computer and use it in GitHub Desktop.
Save joram/bc02b97805f5b2fde151d74c34a4c434 to your computer and use it in GitHub Desktop.
Battlesnake thoughts

Battlensake Architecture

  • It should be written as several microservices, so we can horizontally scale when needed.
  • These microservices should be combinable into native binaries for ease of use locally.

Game Storage

This should be abstracted so we can replace the datastore with an in ram db, S3, or other, depending on usage. The storage models would be:

GameConfiguration:
  width int
  height int
  food_count int
  snake_ids list<string>
  snake_timeout_ms int

InitialGameState:
  snake_coords map<string, coord>
  food_coords list<coord>

GameStateDelta:
  new_food_coords list<coord>
  sname_moves list<enum> (UP, DOWN, LEFT, RIGHT, DEAD, ERROR)
  
Game:
  config GameConfiguration
  initial IntialGameState
  deltas list<GameStateDelta>
  state string (COMPLETE, RUNNING, PAUSED)

A game should not be able to be paused in the production system, only on a local debugging system.

Game Processing

This should be written to handle a single game tick. This allows the freedome to distribute each tick, or run the full game locally, then save.

Web API (api.battlesnake.io)

this should be where we serve:

  • CRUD games, including
  • all game deltas
  • full board states

Web

veteran flare

If we can track who played in previous years, we can allow them a piece of flare like extra head/tail images, or a hat. We could even do custom ones for previous winners.

Bountysnakes

If we define a new exposed endpoint for snakes, which we only talk to if they are bounty snakes, we can build those pre-configured game types in the UI for them. i.e. GET /bounty-games responds with

[
{"name": "Round 1", "width": 20, "height": 20, "snakes":[our_url, COMPETATOR_URL], ...},
{"name": "Round 2", "width": 10, "height": 10, "snakes":[our_url, COMPETATOR_URL, COMPETATOR_URL], ...},
{"name": "Round 2", "width": 10, "height": 5, "snakes":[our_url, our_url, COMPETATOR_URL, COMPETATOR_URL], ...}, ...}
]

/end

serving the same data as /move to /end, except for the state you died on. and add in your snake details to the list post, with no response

Native binaries

  • build/publish a seperate binary for each os for local testing.

Community Training ground

setup something like play.snakedown.com

Microservices in a mono-repo

  • game history storage
  • game execution
  • auto-running training games
  • local testing UI
  • website UI

Game Details to keep in mind

  • Spawning on edges is bad
  • Spawning adjacent to snakes/food is bad
  • Spawning on one colour of a checkerboard is ok? (head-on-head can’t happen)
  • checkerboard problem can be solved if neck-neck collisions are considered head-head
  • {“data”: {...}} everywhere sucks

Containerized Snakes

For junior folk, removing the barrier of deploying your code to a production system is a challenge. If we had them link their repo (and we provided base snakes with Dockerfiles) then we could build and deploy docker images to something like ECS. That said we should still allow the option of self deployed snakes, since devs like their freedoms, and containerized snakes limits resources (and costs us).

Competator User Stories "As a sponsoring team I want to..."

  • create a team
  • add team members to a team
  • remove team members
  • edit team details
    • team name
    • team description
    • snake url
    • competition bracket
  • crud snakes
  • mark a single snake as my primary snake
  • mark snakes to be:
    • hidden/visible
    • training (run arbitrary games against this snake)
  • stop training automatically if the snake consistently doesn't 200.
  • have simple sanity checks run against each snake regularly (edge case checker)
  • register for the upcoming tournament

Bountysnake User Stories "As a sponsoring team I want to ..."

  • do all competator stories
  • NOT have my snake compete in the tournament
  • have my team members to be able to be in other teams
  • define arbitrary game configurations (including number of competator snakes) for bounty games
  • define win condition text
  • define win condition code (to verify the win condition has been met)
  • easily find competatotor snakes to run bounty games against
  • run bounty games
  • have a stored list of all snakes/teams that have beaten a bounty

Event Coordinator User Stories "As an event coordinator I want to ..."

  • mark/control teams as attending the event
  • get a count of active (and check passing) snakes in each competition bracket
  • create a tournament tree for each competition bracket
  • run each game in a heat (remove the top snake each time)
  • have a pretty view of the tournament tree from which we can run each heat/game
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment