Game API

General rules applicable for Codyfight game API

  • API URL: https://game.codyfight.com
  • Response content type: application/json
  • One concurrent request per one CKey is allowed
  • Each request parameter is also accepted as a body parameter
  • Game API is accessed using HTTP Methods (POST, GET, PUT, DELETE)

Read more on how to play in the documentation below!

  • INIT GAME HTTP POST

      DESCRIPTION

      Start a new game by the given mode. Use your robot CKey obtained during the registration. The matchmaking process can take up to few minutes, depending on the chosen game mode.

      PARAMETERS

      Type Parameter Value
      string ckey Robot CKey
      integer mode Game matchmaking mode: 1 #custom, 2 #random, 3 #arena
      string opponent Optional. Codyfighter name in #custom game.

      REQUEST EXAMPLE

      Matchmaking with custom codyfighter
      POST https://game.codyfight.com?ckey=xxx&mode=1&opponent=foo

      Matchmaking with random codyfighter
      POST https://game.codyfight.com?ckey=xxx&mode=2

      Arena: rank-based matchmaking
      POST https://game.codyfight.com?ckey=xxx&mode=3

      RESPONSE EXAMPLE

      HTTP Code: 200
      Body:

      HTTP Code: 400
      Body:

  • CHECK STATE HTTP GET

      DESCRIPTION

      Get a current game state for the given codyfighter. Use this endpoint to check whether any action is required or analyze the latest state.

      PARAMETERS

      Type Parameter Value
      string ckey Robot CKey

      REQUEST EXAMPLE

      Fetch current game state
      GET https://game.codyfight.com?ckey=xxx

      RESPONSE EXAMPLE

      HTTP Code: 200
      Body:

      Response Code: 400
      Body:

  • MOVE ROBOT HTTP PUT

      DESCRIPTION

      Perform codyfighter movement to the map position x & y. Use this endpoint when robot action is required.

      PARAMETERS

      Type Parameter Value
      string ckey Robot CKey
      integer x Agent position x value on the map
      integer y Agent position y value on the map

      REQUEST EXAMPLE

      Move robot to the position (3, 3)
      PUT https://game.codyfight.com?ckey=xxx&x=3&y=3

      RESPONSE EXAMPLE

      HTTP Code: 200
      Body:

      HTTP Code: 400
      Body:

  • SURRENDER HTTP DELETE

      DESCRIPTION

      Leave the game in hopeless situation.

      PARAMETERS

      Type Parameter Value
      string ckey Robot CKey

      REQUEST EXAMPLE

      Surrender current game
      DELETE https://game.codyfight.com?ckey=xxx

      RESPONSE EXAMPLE

      HTTP Code: 200
      Body:

      HTTP Code: 400
      Body:

Pseudo Codyfighter

Implement this pseudo code with any programming language you like. Perform HTTP requests to the game API in a sequence as described below.

Please note that Codyfight server will hold your request (up to 1000 ms) until bearer action is required. Whenever a server responds that bearer.is_action_required is false, perform a new GET request to retrieve the latest game state.

      
  /** your codyfighter identification */
  const ckey = 'xxx';

  /** start a new game */
  var game = init(ckey);

  /** players registering */
  while (game.state.status === 0) {
    game = check(ckey);
  }

  /** game in progress */
  while (game.state.status === 1) {
    if (game.robots.bearer.is_action_required) {
      // var x = ...
      // var y = ...
      // pick a move from game.robots.bearer.possible_moves
      game = move(ckey, x, y);
    } else {
      game = check(ckey);
    }
  }

  /** the game has ended */
  if (game.state.status === 2) {
    // check winner in game.verdict
  }

  /**
   * TODO: implement these functions
   *
   * 1. init(ckey)
   *  - HTTP POST game.codyfight.com
   *
   * 2. check(ckey)
   *  - HTTP GET game.codyfight.com
   *
   * 3. move(ckey, x, y)
   *  - HTTP PUT game.codyfight.com
   *  - sophisticated algorithm to determine movement position x & y
   */
      
    

Visit official game client for coding example