We will design a program that enables two people to play a game of Tic Tac Toe over the Internet. You will use localhost, as described in class, to simplify grading. You will start the server program from a command prompt. It will alert that it is ready to accept players for the game. You will then start two clients from different command prompts. They will issue the join message with their player name as a command to join the game. The server will check to see how many players it has and spawn threads for the first two to join. After that, the server will politely decline to let additional players join (unless you choose to extend the functionality to allow multiple games and players in pairs). Once the game has two players, the server program will accept move commands with three parameters: the player number (1 or 2), the row of the Tic Tac Toe board (0, 1, or 2) and the column of the board (0, 1, 2).

So, our Network Tic-Tac-Toe protocol (N3TP) is

  • Client Message: join < name>. Server Response: join < name>Hello < name> you are player < number> or We already have two players for this game. Meaning: First or second player joining the game, Third player has executed a "join" command.
  • Client Message: choose < int> < int> < int>. Server Response: We do not have two players yet or Player < int> has chosen < int> < int> or Position < int> < int> is taken, try again or Not Player < int> turn or Player < int> WINS!!! or Illegal player number or Illegal Board Position. Meaning: Need a second player to start, Legal move - not the end of the game, Position has been selected, Must strictly alternate turns, Winner, Bad input data, Bad input data.
  • Client Message: quit. Server Response: Player < int> has quit. Meaning: Game over

Notes:

  • The goal is to establish the ability to play one game between two players. The server does not have to continue after that - you can kill the server at that point. After the game or a QUIT command, you can kill the server and start over.
  • Some of these features are more difficult to implement than others. I will provide guidance and possibly modify some of the error checking going forward.
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.