The purpose of this lab is to integrate the core language constructs of C++ learned in CISC1600.

The assignment is to write a program to play the game of Tic Tac Toe. The game should allow for two players to play each other. You can choose whether player X or player O begins. The players continue to take turns until the first player gets three in a row or until there is a stalemate where no one can win.

The program should begin with a welcome message indicating the purpose of the program. To begin the game, the program should display the initial (empty) board. It should then prompt each player to enter the space they would like to move to. If the space is free, the move should be accepted else, the move should be rejected and they should be prompted to enter another space. The program should display the updated board with each accepted move. When appropriate, the program should check the board for a winner. If the program finds three in a row it should congratulate the winner and exit (or see bonus).

In summary the program should:

  • maintain the configuration of the board as the game goes on
  • prompt the users to enter their moves in alternate turns
  • check whether the move is legal (a move cannot be made to a space that is occupied)
  • display the newly updated board
  • check for a winner and declare the player that won if one is found
  • If all squares on the board have been occupied without a winner, the program should announce a stalemate.

Following is an example run:

Welcome to ...
+--+--+--+
|__|__|__|
+--+--+--+
|__|__|__|
+--+--+--+
|__|__|__|
+--+--+--+

Player O Enter your move: 1,1
+--+--+--+
|O_|__|__|
+--+--+--+
|__|__|__|
+--+--+--+
|__|__|__|
+--+--+--+

Player X Enter your move: 2,2
+--+--+--+
|O_|__|__|
+--+--+--+
|__|X_|__|
+--+--+--+
|__|__|__|
+--+--+--+

Player O Enter your Move: 1,2
+--+--+--+
|O_|O_|__|
+--+--+--+
|__|X_|__|
+--+--+--+
|__|__|__|
+--+--+--+

Player X Enter your move: 1,2
No No Player X that spot is occupied!

Player X Enter your move:5,2
Oh c'mon really? At least choose a move on the board!

Player X Enter your move:1,3
+--+--+--+
|O_|O_|X_|
+--+--+--+
|__|X_|__|
+--+--+--+
|__|__|__|
+--+--+--+

Etc...

NOTE: Alternatively, you can make your program friendlier by numbering each empty square and allowing the user to name the square using that number instead of entering of the row number and col number of the square. The following is a nice naming scheme:

+--+--+--+
|1_|2_|3_|
+--+--+--+
|4_|5_|6_|
+--+--+--+
|7_|8_|9_|
+--+--+--+

Bonus: At the end of each game have the program prompt (the players) if they want to play another game. If they enter in the affirmative i.e. (y/Y)es the program should continue and play another game of tic tac toe, else the program should politely exit. Keep track of the number of times that each player wins and print out summary results when they no longer want to play the game.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only 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 fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.