Objectives and Overview: Recuresion is a very valuable tool in computing. In this lab, you will gain experience writing recursive functions, as well as evaluating recursive problem solutions. The venerable game of Tic Tac Toe is used to illustrate the main ideas.
The file TicTac.h provide a complete class with functions that allow a program to simulate the tic tac toe game. The file tictactoe.cpp is a sample simulation which pits the human player against the computer, with the computer choosing an optimal move for itself at each turn. Copies of these files are available in the CS210 (Tucker) folder.
Set up a CodeWarrior project with these two files, and make and run
the program. The following example shows the dialog that would occur during
a typical game (here, C = the computer player and H = the human player,
who had originally made the first move):
Computer's move (value = 1): C| | ----- H|C| ----- | |H Enter row and column (0, 1, 2) of move: 1 2 Thank you! C| | ----- H|C|H ----- | |H Computer's move (value = 3): C| |C ----- H|C|H ----- | |H Enter row and column (0, 1, 2) of move: 0 1
Run this program several times, including once for the run that is reflected above. After reading over the program and the TicTacToe class, answer the following questions:
H|C|H ----- |C| ----- | |H
Computer's move (value = 3): C|H| ----- C| | ----- | |
Taking advantage of the ChooseMove function, revise the tictactoe.cpp program so that it monitors a game of Tic Tac Toe between two human players. That is, the program should get each player's move in turn (one player assumes the role of C and the other the role of H). It should evaluate each player's proposed move and suggest that the player try again if the best possible alternative move hasn't been chosen. The program should not give away the best move to either player.
When extended in this way, the program is able to help each player avoid making moves that lead to a loss. This is an elementary example of a teaching program, since it gives advice to players that can help improve their performance.
Submit your program for Part 2 of this lab by dragging it to the CS210 (Tucker) -> Drop Box folder. Don't forget to rename this fileby affixing your name to it.
Also, hand in hard copy listing of your program with your name on it, along with your answers to the questions in Part 1.
You may work on the programming part of this lab in teams of two, but all answers to these questions should be developed individually.