Skip to content
Soarez edited this page Sep 20, 2012 · 8 revisions

ZD Backend API spec

POST /games

Start -- Create a game.

Request
{
  "nickname": "Rulio"
}
Response

The result should be something like this.

{
  "id": "PbDHs",
  "nickname": "Rulio",
  "score": 0,
  
  "vp": 0,
  "rounds": 0,
  
  "rolled": [
    { "color": "red", "face": "shot" },
    { "color": "green", "face": "runner" },
    { "color": "yellow", "face": "brain" }
  ],
  "brains": ["yellow"],
  "shots": ["red"],
  "runners": ["green"]
}

The last three fields are arrays of the dice's colors.

  • score is the number of accumulated brains.
  • vp is the number of victory points, earned each time the score reaches 13.
  • rounds is the number of times the player is shotgunned (three shots), or eats 13 (or more) brains.

When the score reaches 13 or more, the player earns a VP and starts a new round with the score reset to zero.

When the player gets three shots, a new round starts with the score intact.

PUT /games/id

Play -- Update the game state.

Request
{
  "id": "PbDHs",
  "nickname": "Rulio",
  "action": "roll",
  
  "vp": 0,
  "rounds": 0,
  "score": 0,
  "brains": ["yellow"],
  "shots": ["red"],
  "runners": ["green"]
}

The server only cares about the three first fields. The nickname can be updated. The action, if any, can be either roll or stop. If no action is provided the server returns 400 Bad Request

Response
{
  "id": "PbDHs",
  "nickname": "Rulio",

  "vp": 0,
  "rounds": 0,
  "score": 0,
  "rolled": [
    { "color": "yellow", "face": "shot" },
    { "color": "green", "face": "brain" },
    { "color": "yellow", "face": "brain" }
  ],
  "brains": ["yellow", "green", "yellow"],
  "shots": ["red", "yellow"],
  "runners": ["green"]
}

This is the response in case the specified action was roll. If the specified action was stop, the rolled would be ommited.

GET /games/id

Just retrieve the state of the game.

Response
{
  "id": "PbDHs",
  "nickname": "Rulio",

  "vp": 0,
  "score": 0,
  "rounds": 0,
  "rolled": [
    { "color": "yellow", "face": "shot" },
    { "color": "green", "face": "brain" },
    { "color": "yellow", "face": "brain" }
  ],
  "brains": ["yellow", "green", "yellow"],
  "shots": ["red", "yellow"],
  "runners": ["green"]
}

GET /ranking

Get the global ranking.

The player with more vp (victory points) to rounds ratio is always first.

Response
[
  { 
    "position": 1,
    "nickname": "Rulio",
    "vp": 23,
    "rounds": 35
  },
  { 
    "position": 2,
    "nickname": "Emilio",
    "vp": 23,
    "rounds": 40
  },
  { 
    "position": 3,
    "nickname": "Emilio",
    "vp": 4,
    "rounds": 8
  },
]
Clone this wiki locally