previous | index | next

The AutomatedPlayerInfo Class

The AutomatedPlayerInfo Class Header

Automated player objects have a strategy object as an instance variable:

class AutomatedPlayerInfo: public PlayerInfo {
public:
  AutomatedPlayerInfo(string name, Strategy strategy);
  Move getMove(GameState state);
private:
  Strategy strategy;
};

getMove implements a more intelligent move strategy than its superclass's version by delegating the work to the strategy object.

Defining the AutomatedPlayerInfo Class Members

AutomatedPlayerInfo::AutomatedPlayerInfo(string name, Strategy strategy) :
  PlayerInfo(name) {
  this->strategy = strategy;
}

Move AutomatedPlayerInfo::getMove(GameState state) {
  return strategy->getMove(state);
}

previous | index | next