PROGRAM DESCRIPTION:

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.

REQUIREMENTS:

  • Your code should be well documented in terms of comments.
  • Your server should be named "minor5server.py", without the quotes.
  • Your client should be named "minor5client.py", without the quotes.
  • Your programs will be graded based largely on whether it works correctly on the CSE machines (e.g., cse01, cse02, ..., cse06), so you should make sure that your scripts do not have any runtime errors and runs on a CSE machine.

General:

  • The server should accept connections from two clients then begin the game.
  • The following commands should be implemented:
  • M< R>< C> - Player places a mark on row R column C.
  • Rows are the letters A, B or C
  • Columns are numbers 1, 2 or 3
  • R - Resign
  • ? - Display Help

Server:

  • Your server should be named "minor5server.py", without the quotes.
  • Should take a port number as a command line parameter.
  • Display commands received from clients.
  • Display responses sent back to the clients.
  • After each valid move the board should be sent to both clients and a message to the other player that it is their turn.
  • The board should have legends for rows and columns (see sample games below).
  • The server should prevent players from going out of turn.
  • When the game ends. The server should send the board and notify each player of the results. (i.e. who won, or tie, resigned, See sample games below).

Client:

  • Your client should be named "minor5client.py", without the quotes.
  • Should take a hostname and a port number as command line parameters
  • Display a message "Connecting to Server"
  • Be able to process commands from the user and messages from the server in any order.
  • The server can send messages at any time that that should be displayed when received.
  • The player can enter commands at any time which should be sent to the server when entered.

SAMPLE OUTPUT (user input shown in bold):

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 M with no spaces
Example: MA1 or MB3
X
O>You win, X resigned
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 M with 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
X
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>That spot is already taken
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
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.