CIS071 Lab08 - Tic Tac Toe (Part 2) DUE: (Friday, Mar 24, NOON)


Tic Tac Toe (Part 2)

 

Objective

In this assignment, you should write a program that

  1. welcomes the players to the game of Tic Tac Toe;
  2. prompts players 1 and 2 to alternatively fill the Tic Tac Toe board with X and O symbols;
  3. checks if there is a winner after each move;
  4. informs the players when the game is over (this can happen if one of the player wins, or if the board is filled and there is a draw).

 

Details

You should write and use the following functions:

void enter_symbol(char tictactoe[][3], int player)

void print_board(char tictactoe[][3])

int if_winner(char tictactoe[][3])

 

Function enter_symbol should prompt player 1 or 2 (described by variable player) to choose a position on the board to fill. In case the desired position is already filled with X or O this function should inform the user that this position is taken, and prompt him to fill one of the available positions. Hint: the function call can look like this: enter_symbol(tictactoe,2), which would prompt player 2 to enter O symbol.

Function print_board should display the current state of the board (similarly to what you did in lab 7), by displaying X, O, or . if the position is not filled yet. (Hint: you should initialize tictactoe array with values .). You should call this function after each move.

Function if_winner should determine if, based on the current state of the board, there is a winner. The function should return 0 if there is no winner yet, 1 if winner is player 1, and 2 if the winner is player 2.

 

Deliverables:
Submit your program; show a few sample runs of the program.

 

 

Extra Credit

Make a program that allows a single player mode of the Tic Tac Toe game. In this case, the first player (that enters Xs) is a user of the program, while the second player (that enters Os) is computer. The challenge is to decide where to enter O after each move by the first player, such that computer tries to prevent the first player from winning. Alternatively, you can also allow the computer to have the first move. You will be graded based on the ability of computer to play the game well against the human opponent.