-
Notifications
You must be signed in to change notification settings - Fork 0
Implementing a Player AI
Phrogz edited this page Oct 28, 2011
·
1 revision
See the RandomMatch Domohnoes player for a simple example. In general, a Ruby player needs to:
- Require the
client.rbfile. - Create a new class subclassing
Laink::Client. - In the class definition call
gametype 'com.foo.bar'to specify the type of game to play. - In the
initializemethod (if any) be sure to callsuper(). - Provide a
namemethod that returns a unique name for this player. - Create a
movemethod that is passed a game state and responds with the details of a move to play.
- The details of the
stateHash and move response depends on the game being played.
Run the client via MyPlayer.new.play_game.
Every client must be able to:
- Create a TCP socket to the server.
- 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).
- Send a
start_gamecommand, identifying the client's name and the type of game to play:
{"command":"start_game", "gametype":"com.foo.bar", "nick":"MasterBlaster"} - Listen for a message containing
{"command":"move", "state":xxx}and formulate a legal responseyyybased on whateverxxxstate the game sent to you. - Send a legal game play to the server move via
{"command":"move", yyy}(whereyyyis whatever complex key/value pair data will be accepted by the game logic. - Listen for a message containing
{"command":"gameover", "winner":"nickname"}and disconnect the socket.