Project 6: Jogo da Velha
We make a network game of Tick-Tack-Toe, Jogo da Velha.
The server starts and waits for a connect. The first letter
sent by the client is X or O, meaning that it wants to play
X or O. Server responds OK. Then the first player send
m n, where m is 1-3 and n is 1-3, the row and column of where
to mark. The second player responds m n. Until one sends
a 0 0 and the game ends.
After each move, print out the game board:
| X |
---+---+---
O | X |
---+---+---
| O |
move (row col)?
Protocol
We decided upon the following protocol for our client/server game.
Each message is a single char followd by a newline (using
println and flush). Characters 1, 2, ..., 9 are the board
positions. Character 0 is reset. WHen in trouble, send a 0.
Client sends an X or O (the lettter) to begin a game.
In response to an X, server sends a *; in response to an O server
sends 1-9 the first move.
Client Server
'X' ->
<- '*'
n ->
<- n
...
'0' ->
<- '0'
'O' ->
<- n
n ->
'Q' ->