The FishNet protocol

Your program (a client) will communicate with another player (also a client) via a server. (See figure below.) The server runs on port 153 of avrim.pc.cs.cmu.edu.

Figure 2: A FishNet game setup.

The server's job is to pair players together, to deal cards, to referee the game, and to notify players of the game's progress. The server keeps track of both players' hands and takes care of the forced communication (replying to requests and revealing books) on its own. It frequently sends information to the clients about the progress of the game, and it prompts the clients to choose which rank to request when appropriate. The client's primary tasks, therefore, are to keep track of what is in the hand (based on the server's messages) and to generate requests when the server prompts the program to do so. Your program may assume the server referees the game properly; very few of the rules will need to be incorporated into the program.

The following is a sample communication session between the server and a client. The server's messages are in boldface type, the client's in normal type. The C++-style comments describe what is happening and are not part of the communication.

play cburch spot  // You identify yourself and who you want to play
fish 3            // Server deals the hand 2,2,3,4,4,9,12 to you
fish 4
fish 2
fish 4
fish 9
fish 12
oppmakes 0        // Spot made a book of four 0s during the deal
fish 2            // You are dealt your seventh card
yourturn          // Server chose you to go first
request 3
oppgives 2 3      // Spot had two of the 3s you requested
yourturn          // Server tells you to go again
request 12
fish 8            // Spot had none; you draw an eight
request 2         // Spot requests 2s (you lose two 2s)
request 2         // Spot requests 2s again (you lose none)
oppmakes 2        // Spot completes a book of four 2s
youlose           // Spot is out; with two books to your none, Spot wins
In this game, Spot receives seven cards in the deal and happens to complete a book of zeroes, leaving three cards. Spot loses two of these when you request 3s, leaving one card. Then, when it becomes Spot's turn, Spot holds a single card. Spot requests 2s, of which you have two. Spot requests 2s again, and of course you have none. But Spot fishes a 2, completing a book. Since Spot fishes the same card as requested, Spot gets another request. But Spot has no cards; thus the game ends. Spot has two books (of 0s and 2s) while you have none, so you lose.

Each FishNet message consists of an operation, followed by some arguments separated by spaces, followed by the end of a line. The following describes operations used in the FishNet protocol. (The only message the server does not send is the play message. The client sends only play, request, and pass messages.)

error
The server sends this message when it encounters a problem, usually because of something your program did. It has a single argument, which is a string with no spaces describing the error. When your program receives this type of message, it should print the error description to the screen and attempt to continue.
fish
The server sends this message whenever you draw a card. The single argument, between 0 and 12, tells the rank of the drawn card.
oppgives
When the opponent has some cards you request, the server sends this message. The first argument tells how many of the cards the opponent gives, and the second argument tells their rank.
oppmakes
The server sends this message when the opponent completes a book. The argument tells the rank of the book.
pass
You may send this message to forfeit a turn. Unless you passed in your last turn also, you do not fish. (A Level 1 program will not use this message.) The server will send this message when your opponent passes.
play
The client sends this message when it wants to begin a game. It has two arguments, both strings. The first should be a name for your team (this name will be part of the program). The second argument is the name of the opponent you would like to play.

When the server receives this request, it sees if it has any opponent by the requested name waiting for you. If so, it begins a game. If not, it sends nothing to the client until an opponent of the desired name requests a game with you. Note that the choice of which opponent goes first is always random.

Built into the server are four players always available to play: spot, bob, alice, smarx (in increasing order of difficulty). The last is the 1998 PGSS Go Fish champion, by Steve Marx.

request
The client sends this message to request a rank, and the server sends this message when the opponent requests a rank. In either case, there is a single argument between 0 and 12 specifying the requested rank. Note that a client does not need to send anything on receiving a request message.
tiegame
The game has ended in a tie game. The server immediately closes the connection after this.
youlose
Your opponent won the game. The server immediately closes the connection after this.
yourturn
The server is asking you what you would like to request. You should respond with either a request or a pass message.
youwin
You have won the game. The server immediately closes the connection after this.