Skip to content

Instantly share code, notes, and snippets.

@danielevans
Created May 12, 2011 07:06
Show Gist options
  • Save danielevans/968072 to your computer and use it in GitHub Desktop.
Save danielevans/968072 to your computer and use it in GitHub Desktop.
JSON api definition for competition server
//ACTION DEFINITIONS
//start_game
{//informs of a game starting
"method": "start_game",
"game": GAME_OBJECT,
"player": PLAYER_OBJECT
}
//response ignored
//act
{//request for an action
"method": "act",
"game": GAME_OBJECT,
"turn": TURN_OBJECT
}
//response
{
"turn": TURN_OBJECT_WITH_ACTION
}
//if the response is invalid, or times out a "nil" move will be selected (forfiet turn in most cases)
//for games with no nil move and it is not possible to forfiet, invalid responses and timeouts will result in game forfeiture
//turn
{//informs of a turn completed
"method": "turn",
"game": GAME_OBJECT,
"turn" : TURN_OBJECT_WITH_ACTION_CONTAINING_RESULT
}
//response ignored
//end_game
{
"method": "end_game",
"game": GAME_OBJECT
}
//response ignored
//OBJECT DEFINITIONS
{//GAME_OBJECT
"type": "russian-roulette",
"id": GAME_ID, //integer
"players": [ PLAYER_OBJECT, PLAYER_OBJECT . . . ],
"state": STATE_OBJECT
}
{//STATE_OBJECT (game specific)
"live_players": [ PLAYER_ID, PLAYER_ID ], //players still in the game
"dead_players": [ PLAYER_ID, PLAYER_ID ]
}
//PLAYER_OBJECT
{
"id": PLAYER_ID, //integer
"player_name": PLAYER_NAME //string
}
{//TURN_OBJECT
"id": TURN_ID //integer
}
{//TURN_OBJECT_WITH_ACTION
"id": TURN_ID
"actions": [ACTION_OBJECT, . . .]
}
{//TURN_OBJECT_WITH_ACTION_CONTAINING_RESULT
"id": TURN_ID,
"actions": [ACTION_OBJECT_WITH_RESULT, . . .]
}
{//ACTION_OBJECT (game specific)
"id": ACTION_ID,
"player_id": PLAYER_ID,
"action": { //whole object gets stored as JSON in a text blob
"shoot": PLAYER_ID
}
}
{//ACTION_OBJECT_WITH_RESULT (game specific)
"id": ACTION_ID,
"player_id": PLAYER_ID,
"action": { //whole object gets stored as JSON in a text blob
"shoot": PLAYER_ID
},
"result": "hit" //or "miss" also all stored as JSON in a text blob, future games result can be object
}
//DATA MODEL
/*
GAME
- id
- type
- has many players
- has many turns
TURN
- id
- game_id
- has many actions
- belongs to GAME
ACTION
- id
- turn_id
- act (full text)
- result (full text)
- belongs to PLAYER
- belongs to TURN
PLAYER
- id
- game_id
- name
- interface_method
- interface_data (specific info for method, like "url" for web based interfaces or "executable" for CLI
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment