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...


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 NimMove 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 TwoPlayerGame 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.

Nov 18, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here