Skip to content

Implementing a Player AI

Phrogz edited this page Oct 28, 2011 · 1 revision

Implementing a Player (Ruby)

See the RandomMatch Domohnoes player for a simple example. In general, a Ruby player needs to:

  1. Require the client.rb file.
  2. Create a new class subclassing Laink::Client.
  3. In the class definition call gametype 'com.foo.bar' to specify the type of game to play.
  4. In the initialize method (if any) be sure to call super().
  5. Provide a name method that returns a unique name for this player.
  6. Create a move method that is passed a game state and responds with the details of a move to play.
  • The details of the state Hash and move response depends on the game being played.

Run the client via MyPlayer.new.play_game.

Implementing a Player (Other Languages)

Every client must be able to:

  1. Create a TCP socket to the server.
  2. Be able to perform blocking read and write over the socket via length-prefixed JSON.
  • Messages in both directions consist of a 2-byte header followed by UTF-8 encoded JSON.
  • The header indicates the number of bytes to follow (bytes in the message not including the header).
  1. Send a start_game command, identifying the client's name and the type of game to play:
    {"command":"start_game", "gametype":"com.foo.bar", "nick":"MasterBlaster"}
  2. Listen for a message containing {"command":"move", "state":xxx} and formulate a legal response yyy based on whatever xxx state the game sent to you.
  3. Send a legal game play to the server move via {"command":"move", yyy} (where yyy is whatever complex key/value pair data will be accepted by the game logic.
  4. Listen for a message containing {"command":"gameover", "winner":"nickname"} and disconnect the socket.

Clone this wiki locally