In this minor, you will write two complete C programs that will allow two players to play the game of network tic-tac-toe. It will include two programs, a server and a client. The server will allow two clients to connect and then will begin the game. The client programs accept input from the player and transmits the command to the server which will execute the commands and send a reply back to the client programs.
The client and server programs are to communicate via the Internet (network) using TCP sockets. Your server should be able to handle commands from either client in any order. Your clients should be able to handle responses from the server or the player. (hint: use select)
The game is for two players on a 3x3 grid. The player who moves first uses X marks. The second player uses O marks. Each player takes turns placing their mark (X/O) on an empty spot on the grid. The game ends when all spots have a mark or either player has 3 marks in a row.
Example Game 1 - Server
$ ./minor4server 1100
Network Server Starting
Waiting on Clients
XX>You are player X. Waiting on player O to connect
OO>You are player O
X> board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
3
X>Your turn
OO>Invalid command
OO>It's not your turn
XX>Invalid Move
Move should be MO>You win, X resigned with no spaces
Example: MA1 or MB3
X
Game Ended
Example Game 1 - First Client
$ ./minor4client cse03.cse.unt.edu 1100
You are player X. Waiting on player O to connect
board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
Your turn
MA5
Invalid Move
Move should be M< R>< C> with no spaces
Example: MA1 or MB3
R
Example Game 1 - Second Client
$ ./minor4client cse03.cse.unt.edu 1100
You are player O
board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
X
Invalid command
MA5
It's not your turn
You win, X resigned
Example Game 2 - Server
$ ./minor4server 1100
Network Server Starting
Waiting on Clients
XX>You are player X. Waiting on player O to connect
OO>You are player O
X> board 1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
X>Your turn
X< MA1 X>
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B| | |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B| | |
+-+-+-
C| | |
O>Your turn
O< MB1 X>
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B|O| |
5
+-+-+-
C| | |
Example Game 2 - Server (continued)
O>
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B|O| |
+-+-+-
C| | |
X>Your turn
XO>That spot is already taken
board
1 2 3
+-+-+-
A|X|X|
+-+-+-
B|O| |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|X|X|
+-+-+-
B|O| |
+-+-+-
C| | |
O>Your turn
O
O< MB2 X>
board
1 2 3
+-+-+-
A|X|X|
+-+-+-
B|O|O|
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|X|X|
+-+-+-
B|O|O|
+-+-+-
C| | |
Example Game 2 - Server (continued)
X>Your turn
X< MA3 X>
board
1 2 3
+-+-+-
A|X|X|X
+-+-+-
B|O|O|
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|X|X|X
+-+-+-
B|O|O|
+-+-+-
C| | |
X>You win
O>You lose
Game Ended
Example Game 2 - First Client
./minor4client cse03.cse.unt.edu 1100
You are player X. Waiting on player O to connect
Board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
Your turn
MA1
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B| | |
+-+-+-
C| | |
Example Game 2 - First Client (continued)
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B|O| |
+-+-+-
C| | |
Your turn
MA2
board
1 2 3
+-+-+-
A|X|X|
+-+-+-
B|O| |
+-+-+-
C| | |
board
1 2 3
+-+-+- A|X|X|
+-+-+-
B|O|O|
+-+-+-
C| | |
Your turn
MA3
board
1 2 3
+-+-+-
A|X|X|X
+-+-+-
B|O|O|
+-+-+-
C| | |
You win
Example Game 2 - Second Client
./minor4client cse03.cse.unt.edu 1100
You are player O
board 1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B| | |
+-+-+-
C| | |
Your turn
MB1
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B|O| |
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|X|X|
+-+-+-
B|O| |
+-+-+-
C| | |
Your turn
MA2
That spot is already taken
MB2
board
1 2 3
+-+-+-
A|X|X|
+-+-+-
B|O|O|
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|X|X|X
+-+-+-
B|O|O|
+-+-+-
C| | |
You lose
Example Game 3 - Server
$ ./minor4server 1100
Network Server Starting
Waiting on Clients
XX>You are player X. Waiting on player O to connect
OO>You are player O
X> board 1 2 3
+-+-+-
A| | |
9
+-+-+-
B| | |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | | X>Your
turn
OO>
?-Display this help
R-Resign
Move< R>< C>-Move where < R> is a row A, B or C andis a column 1,2 or 3
Example Moves: MA1 MC3 MB1
X< MA2 X>
board
1 2 3
+-+-+-
A| |X|
+-+-+-
B| | |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A| |X|
+-+-+-
B| | |
+-+-+-
C| | |
O>Your turn
Example Game 3 - Server (continued)
OX>
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B| | |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B| | |
+-+-+-
C| | |
X>Your turn
X< MB1 X>
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B|X| |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B|X| |
+-+-+-
C| | |
O>Your turn
OX>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
Example Game 3 - Server (continued)
B|X| |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X| |
+-+-+-
C| | |
X>Your turn
X< MB3 X>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X| |X
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X| |X
+-+-+-
C| | |
O>Your turn
OX>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
Example Game 3 - Server (continued)
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C| | |
X>Your turn
X< MC1 X>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X| |
O>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X| |
O>Your turn
Example Game 3 - Server (continued)
X>
board
1 2 3
+-+-+A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|
O>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|
X>Your turn
X< MC3 X>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|X
O>
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|X
X>Tie game
O>Tie game
Game Ended
Example Game 3 - First Client
./minor4client cse03.cse.unt.edu 1100
You are player X. Waiting on player O to connect
board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | |
Your turn
MA2
board
1 2 3
+-+-+-
A| |X|
+-+-+-
B| | |
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B| | |
+-+-+-
C| | |
Your turn
MB1
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B|X| |
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X| |
+-+-+-
C| | |
Your turn
Example Game 3 - First Client (continued)
MB3
Board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X| |X
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C| | |
Your turn
MC1
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X| |
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|
Your turn
MC3
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|X
Tie game
Example Game 3 - Second Client
./minor4client cse03.cse.unt.edu 1100
You are player O
board
1 2 3
+-+-+-
A| | |
+-+-+-
B| | |
+-+-+-
C| | | ?
?-Display this help
R-Resign
Move< R>< C>-Move where < R> is a row A, B or C and < C> is a column 1,2 or 3
Example Moves: MA1 MC3 MB1
board
1 2 3
+-+-+-
A| |X|
+-+-+-
B| | |
+-+-+-
C| | |
Your turn
MA1
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B| | |
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|O|X|
+-+-+-
B|X| |
+-+-+-
C| | |
Your turn
Example Game 3 - Second Client (continued)
MA3
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X| |
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X| |X
+-+-+-
C| | |
Your turn
MB2
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C| | |
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X| |
Your turn
Example Game 3 - Second Client (continued)
MC2
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|
board
1 2 3
+-+-+-
A|O|X|O
+-+-+-
B|X|O|X
+-+-+-
C|X|O|X
Tie game