No Tipping Game Architecture


Connections

The No Tipping Game applet expects that player programs create server sockets to listen for, and eventually accept, incoming connections on a specific port. Once the game applet connects with both player programs the game will begin.

All communication between player programs and the applet is done via these sockets using a custom protocol. When it's a player's turn the game applet will send the game state to the player. Once the game state is received the player responds by sending its move back to the game applet. It will then again wait for the next game state to arrive. This loop continues until the game is over.

Basically:

accept incoming socket connection on a given port
while game is not over:
    read game state from socket
    if adding mode
          pick a weight and location to place it on the board
    if removing move
          pick a weight and location to remove from the board
    send move to applet via socket
close the socket


Game State

The game state consists of several lines of text. The first line indicates the current mode of the game; this will be either ADDING or REMOVING. The next fifteen lines contain information about the current status of each of the weights, one per line. The format for these fifteen lines is:

place position owner mass

Where:
place is 0 if the weight has not been placed, 1 if the weight is on the board, and 2 if it has been removed.
position is the location (an integer between -10 and 10) where the weight can be found, if it is on the board.
color is either Red, Blue, or Green.
mass is the size of the weight.

The game state ends with the line STATE END.

EXAMPLE 1:

ADDING
0 0 Red 1
0 0 Blue 1
0 0 Red 2
0 0 Blue 2
0 0 Red 3
0 0 Blue 3
0 0 Red 4
1 -2 Blue 4
0 0 Red 5
0 0 Blue 5
1 -1 Red 6
1 -6 Blue 6
1 -3 Red 7
0 0 Blue 7
1 -4 Green 3
STATE END

This example shows that we are in the ADDING mode, that Red has placed weights 6 and 7 at positions -1 and -3 respectively, and that Blue has placed weights 4 and 6 at positions -2 and -6 respectively. All other weights have not yet been placed. Note that this list also contains the line that Green weight 3 is placed at position -4. Also note that the game state does not include the fact that the board has a weight of 3 which is considered to be at position 0.

EXAMPLE 2:

REMOVING
2 0 Red 1
2 0 Blue 1
2 0 Red 2
2 0 Blue 2
2 0 Red 3
2 0 Blue 3
2 0 Red 4
1 -2 Blue 4
2 0 Red 5
2 0 Blue 5
1 -1 Red 6
1 -6 Blue 6
1 -3 Red 7
2 0 Blue 7
2 0 Green 3
STATE END

This example shows that we are in the REMOVING mode, that Red still has weights 6 and 7 at positions -1 and -3 respectively, and that Blue still has weights 4 and 6 at positions -2 and -6 respectively. All other weights have been removed, including the Green weight.


Sending Moves

Sending a move is very simple. It consists of sending one line of text containing two integers. The first integer is the position, and the second is the weight. For example, in ADDING mode, sending 0 5 will place weight 5 at position 0. Or, in REMOVING mode, sending the same command 0 5 will remove a weight with mass equal to 5 from position 0.

If the move sent is illegal -- i.e placing a weight in a position where a weight already has been placed, or removing a weight from a location where no weight exists -- then the applet will simply resend the game state to the player who issued the illegal move. (And hopefully this player won't respond by sending the same illegal move again.)


Running the Applet Yourself

  1. Download the NoTipping Java Archive.
  2. Run the applet by invoking: java -cp notipping.jar NoTippingApplet
  3. Human players can simply begin playing, or you can connect to player servers by entering hostname and port and then clicking 'connect'.


Player Server Tools

The following links will show how to write a player server in both Python and Java.


Don't Forget!


jason reisman (jasonr%nyu.edu)