In this minor, you will write two complete python 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.
General:
Server:
Client:
Example Game 1 - Server
$ python minor5server.py 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
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
$ python minor5client.py 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 Mwith no spaces
Example: MA1 or MB3
R
Example Game 1 - Second Client
You are player O
board
1 2 3
+-+-+-
A| | |
+-+-+-
4
B| | |
+-+-+-
C| | |
X
Invalid command
MA5
It's not your turn
You win, X resigned
Example Game 2 - Server
$ python minor5server.py 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
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B| | |
+-+-+-
C| | |
O>
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B| | |
+-+-+-
C| | |
O>Your turn
O
board
1 2 3
+-+-+-
A|X| |
+-+-+-
B|O| |
+-+-+-
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
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
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
$ python minor5client.py 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
$ python minor5client.py cse03.cse.unt.edu 1100
You are player O
board 1 2 3
8
+-+-+-
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