You can use either 3dttt.lisp or TTTPlayer.java as a
basis for your own player, or you can make your own. You may find it
easier to work in a dynamically typed --- rather than statically typed
--- language (try for instance Python).
NAME - set our name to ( can be "ANY")The player who joins a game second is X and goes first. Responses from the server are generally of the form "OKAY <...>" for a successful command and "ERROR <...>" for a failure. When playing, you will receive "MOVE <...>", "TIE <...>", and "WIN <...>" as well. When watching, you will receive "GAME O" or "GAME X" messages.
PLAY - play a game against ( can be "ANY")
MOVE - make move
LIST - list available players
WATCH - watch
QUIT - exit
The interface for your code is simple. 3dttt.lisp/TTTPlayer.java provides utilities to interact with the server. If you use the given code, all you need to do to create a player is create a (new-game) and (make-move last-move board) function (there are analogues in the Java version) . The first parameter will be the latest move in the game, and the second parameter will be a 64-element array where 0s are blank spaces, 1s are your spaces, and -1s are your opponent's. The return value of this function must be an integer between 0 and 63, as the board is represented as a one-dimensional array on the server and client alike. The reasoning for passing both the latest move and the board array to your function is that you may like to keep an internal board representation aside from the array, so this will allow you to update it. spot.lisp is a player that completely ignores the board array while keeping an internal representation.
This function connects to the server. Its return value is the socket stream used for communication with the server. You can ignore this return value; it's only useful for debugging purposes. You can also ignore the optional arguments, as the server should always sit on cycle1:6666.
Login as the given name. Returns true upon success.
This function disconnects us from the server. Please use this when you are reloading the code or exiting the lisp interpreter, as resources may fail to be reclaimed by the server otherwise.
This function returns a list of players on the server. Each entry contains the name of a player, optionally followed by a tab, "wf" or "p", another tab, and then the name of a second player. The notation "wf" means the player waits for the second. "p" means the player is playing the second.
Play a game against the named player. Keep in mind that humans must have "[H]" attached to the end. Returns -1, 0, or 1, for loss, tie, and win, respectively, or NIL if an error occurs. This function will call the user-provided function (new-game) before the game is started, and then it will make repeated calls to the user-provided function (make-move last-move board).
(load "3dttt.lisp")
(load "spot.lisp")
(3dttt:connect)
(3dttt:login 'spot)
(3dttt:play-game 'fluffy)
The program will then ask you for your name, attaching "[H]" to the end to indicate the player is human. Upon successful login, the program will then prompt you for a player name to play against. Players can be chosen from the provided list or typed in by hand. "ANY" is the default choice.
The
program will ask you for a currently logged-in player to watch. From
then on, all games played by that player will be displayed as they
happen.