Question
Integrate the code for G Fillable from Figure into the G Object hierarchy. Write a test program that displays both filled and outlined shapes. In
Integrate the code for G Fillable from Figure into the G Object hierarchy. Write a test program that displays both filled and outlined shapes.
In its discussion of recursive backtracking, Chapter 9 offered a general outline for creating two-player games based on the minimax algorithm. At that point in the text, it was difficult to encapsulate the code for the minimax algorithm in a way that would allow the code to be shared by many different games. The combination of templates and inheritance make it much easier to define a base class for two-player games that is easy to extend for particular games. Design and implement a template class called Two Player Game that takes the type used to represent a move as a template parameter. Specific games can then extend that class by overriding the methods that pertain only to that game, leaving intact the methods that implement the minimax algorithm itself. For example, the class definition for the simple Nim game described in Chapter 9 would look like this:
The Nim Move type is defined in the same way that the Move type was in the implementation of the Nim game. In Chapter 9, the code for the minimax algorithm required that type to be named Move. Specifying template parameters makes it possible to use a name that is more descriptive. Test your implementation of the Two Player Game class by completing the definition of the Nim class. Once you have a working implementation of Nim, demonstrate the flexibility of your class by using it to implement one of the other two-player games described in the exercises in Chapter 9.
Integrate the code for G Fillable from Figure into the G Object hierarchy. Write a test program that displays both filled and outlined shapes.
In its discussion of recursive backtracking, Chapter 9 offered a general outline for creating two-player games based on the minimax algorithm. At that point in the text, it was difficult to encapsulate the code for the minimax algorithm in a way that would allow the code to be shared by many different games. The combination of templates and inheritance make it much easier to define a base class for two-player games that is easy to extend for particular games. Design and implement a template class called Two Player Game that takes the type used to represent a move as a template parameter. Specific games can then extend that class by overriding the methods that pertain only to that game, leaving intact the methods that implement the minimax algorithm itself. For example, the class definition for the simple Nim game described in Chapter 9 would look like this:
The Nim Move type is defined in the same way that the Move type was in the implementation of the Nim game. In Chapter 9, the code for the minimax algorithm required that type to be named Move. Specifying template parameters makes it possible to use a name that is more descriptive. Test your implementation of the Two Player Game class by completing the definition of the Nim class. Once you have a working implementation of Nim, demonstrate the flexibility of your class by using it to implement one of the other two-player games described in the exercises in Chapter 9.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started