Game API

Version 1.1

About

Game API is a simple wrapper for the famous game Go and Chess. It provides a basic room manager as host of the games and sits on the websocket protocol as communication interface.

The purpose of this api is learning how to create a good Game-AI and how to beat your enemies ass. If you want to see your ai play or want to play against the ai, try the basic go interface here.

Getting Started

Websocket

As mentioned before, the websocket protocol is used for communication.

URL
Connect to wss://vg-development.de:8900/game

Format

Every message must be valid json and every response will be valid json.
The default template will be like this:

{
    'method': Type of method
    'data': Data from request/response
}                        
Rules
  • Do not abuse bugs. Report them here
  • Every invalid move will be a lost
  • Do not spam requests

Workflow

Methods

Method Type Description
init Response only Returns the current version of the api after connect
{
    'method': 'init',
    'data': {
        'version': version
    }
}                        
error Response only Returns the error after an unsuccessful request
{
    'method': 'error',
    'data': {
        'error': error
    }
}                        
auth-guest Request and Response Login as guest (required for almost every action)
Request
{
    'method': 'auth-guest',
    'data': {
        'username': username
    }
}                        
Response
{
    'method': 'auth-guest',
    'data': {
        'username': username,
        'role': role
    }
}                        
auth-logout Request and Response Logout
Request
{
    'method': 'auth-logout',
    'data': {}
}                        
Response
{
    'method': 'auth-logout'
}                        
room-all Request and Response Returns a list of all available rooms
Request
{
    'method': 'room-all',
    'data': {}
}                        
Response
{
    'method': 'room-all',
    'data': {
        'rooms': [
            {
                //room
            },
            ...
        ]
    }
}                        
room-add Request and Response Add a new room and join
Request
{
    'method': 'room-add',
    'data': {
        'name': name,
        'password': password, //can be an empty string
        'game': game //name of the game (see games below)
    }
}                        
Response
{
    'method': 'room-add',
    'data': {
        //room
    }
}                        
room-join Request and Response Join an existing room
Request
{
    'method': 'room-join',
    'data': {
        'room': room-name,
        'password': password, //can be an empty string
    }
}                        
Response
{
    'method': 'room-join',
    'data': {
        //room
    }
}                        
room-leave Request and Response Leave the room
Request
{
    'method': 'room-leave',
    'data': {}
}                        
Response
{
    'method': 'room-leave',
    'data': {
        //see room-all response
    }
}                        
room-update Response only Send after each change in the current room
Response
{
    'method': 'room-update',
    'data': {
        //room
    }
}                        
room-command Request only Send possible commands for room
Response
{
    'method': 'room-command',
    'data': {
        'command': command //room command
    }
}                        
role-change Request and Response Change role (User need to be in a room)
Request
{
    'method': 'role-change',
    'data': {
        'role': role-id
    }
}                        
Response
{
    'method': 'role-change',
    'data': {
        //user
    }
}                        
game-move Request and Response Send a move
Request
{
    'method': 'game-move',
    'data': {
        'move': move //see valid moves in the game(s) below
    }
}                        
Response
{
    'method': 'game-move'
}                        

Room Manager

The room manager provides a wrapper for basic interaction and consist of a User Model, Room Model and manages the Games.

User

{
    'name': username,
    'ready': true/false, //true if player is ready
    'role': role //as string
}               

Room

{
    'name': room-name,
    'password': true/false //true if password length > 0
    'deadline': {
        'date': date, //date when deadline will be reached
        'duration': duration //(in seconds) timer duration
    },
    'players_ready': true/false, //true if every player is ready
    'game': game //current game state
    'users': [...] //list of users in room
}               

Roles
[ENUM] = [role-id] = [role as string]

  • PLAYER_WHITE = 1 = "white"
  • PLAYER_BLACK = 2 = "black"
  • PLAYER_SPECTATOR = 3 = "spectator"

Room Commands

  • CMD_READY = "ready" (set player ready)
  • CMD_SET_DEADLINE_DUR = "set-deadline-dur [number]" (change deadline duration)
  • CMD_SURRENDER = "surrender" (surrender game)
  • CMD_RESTART = "restart" (restart game)

Go

Rules and gameplay are explained in this article. Every interaction will be send over game-move

Move
Every move on the field must have the following format:
Format: LN (L=a-z, N=1-19, the range depends on the field size)

Possible Commands
  • pass (no move)

State
{
    'name': 'go-[width]x[height]',
    'count': turn_count,
    'turn': turn, //color of player as number
    'width': width,
    'height': height,
    'last_move': last_move, //last game-move
    'pieces': [
        {...}, //go-piece
    ],
    'state': {
        'game_state': state, //state of game
        'black': {
            'pass': true/false, //did the player pass
            'captured': captured, //amount of captured pieces
            'score': score //amount of points (will be calculated after the game)
        },
        'white': {
            'pass': true/false, //did the player pass
            'captured': captured, //amount of captured pieces
            'score': score //amount of points (will be calculated after the game)
        }
    }
}               

Go-Piece
{
    'color': color //number,
    'x': x, //0-based
    'y': y //0-based
}               

Colors
  • COLOR_EMPTY = -1
  • COLOR_WHITE = 0
  • COLOR_BLACK = 1

Game States
  • STATE_OK = 1
  • STATE_ERROR = 0
  • STATE_WHITE_WON = 20
  • STATE_BLACK_WON = 21
  • STATE_JIGO = 3

Chess

Rules and gameplay are explained in this article. Every interaction will be send over game-move

Move
Every move on the field must have the following format:
  • XY-XY   From-To, X=a-h, Y=1-8
  • XY-XY F   Swap Pawn F=(r-rook, b-bishop, k-knight, q-queen)

State
{
    'name': 'chess',
    'count': turn_count,
    'turn': turn, //color of player as number
    'width': width,
    'height': height,
    'last_move': last_move, //last game-move
    'pieces': [
        {...}, //chess-piece
    ],
    'state': {
        'game_state': state, //state of game
        'black': state, //state of black
        'white': state //state of white
    }
}               

Chess-Piece
{
    'color': color //number,
    'x': x, //0-based
    'y': y, //0-based
    'type': type, //piece type
    'out': true/false, //true if piece has been captured
    'move_count': count //amount of move operations on this piece
}               

Colors
  • COLOR_WHITE = 0
  • COLOR_BLACK = 1

Game States
  • STATE_OK = 1
  • STATE_WHITE_WON = 4
  • STATE_BLACK_WON = 3
  • STATE_WHITE_WON_STALE = 6
  • STATE_BLACK_WON_STALE = 5
  • STATE_REMIS = 2

Player States
  • PLAYER_OK = 1
  • PLAYER_CHECK = 0

Piece Types
  • PAWN = 1
  • ROOK = 2
  • BISHOP = 3
  • KNIGHT = 4
  • QUEEN = 5
  • KING = 6

Version Notes

Version 1.1
  • Game: Chess
  • Room Commands
  • Deadline (Timer)
  • Room Commands will replace commands over moves