|
|
Program 3 - January 29This assignment will be your first opportunity to develop an object-based program. It is based on assignment 6.16, on page 414 of the text, but has some differences which are intended to make it both easier and a better vehicle for learning proper design an object that will be useful in solving a variety of problems. Tic Tac ToeThere are a variety of programs one might right based on the game of tic-tac-toe. You could simulate various winning strategies and evaluate which is best. You could simply display moves made by two human players after validating that they are legal. You could display a board as text or in a graphics window. All of these programs have in common that they would benefit from the use of an object which represents a tic-tac-toe game position. For this assignment, you will design and program such an object. In order to test it, you will write a program that accepts moves alternately from two players and displays the board board position. The program should also detect that the game has been won or drawn and announce it. You will turn in two things for this assignment, and both count toward your grade:
The first item must be turned in at the start of class. If you turn in a design, I'll give some leeway on completing the other two parts. Some time will be allowed in class to work on this program after we discuss the designs. DesignIn order to design an object's internal structure, you first must determine what it looks like and does from the outside. Objects of class TicTacToe will represent the current state of a TicTacToe game. To provide an initial design, answer the following questions in writing:
Please provide your design answers in a separate document - text format or word. Note that this contradicts instructions I gave in class saying you could place them in a comment - I prefer that you do this completely before writing any code at all. ImplementationDevelop a header (.h) file that completely describes your class. Develop an implementation file (.cpp) that contains definitions for all your functions. Note that the name of the class must be TicTacToe because we will be doing some exercises that depend on your use of this name. You did an external design in the previous step. To implement the class, you have to decide what internal representation to give for the data. The description for exercise 6.16 tells you to use a 3x3 array with the numbers 1 and 2 representing the two players. You don't have to do it this way - and this may not be the best way. Give some thought to the internal representation that makes it easiest for you to provide the public information that the object is responsible for. The most complex internal task will be to figure out whether anyone has won the game yet, so you may want to think about how you would do that using various internal structures. Test ProgramThe program that tests out your class should be placed in a separate file. In later exercises, you may be using your class with other main programs. The suggested outline for the test program is as follows:
Note that you will have to decide how to display the board. It should be updated each time a move is made and the display should make it easy for a player to indicate the next move. Note that you are not to develop a computer program that plays tic-tac-toe for this exercise. Your class should not know how to select moves because that would violate the encapsulation of the class as we are designing it. We will develop another object in class which understands how to choose good moves, and uses the TicTacToe class to get information for that purpose. |
|
Copyright © 2000 Charlie Poole. All rights reserved.
|