/* * player.hpp * * Created on: Oct 10, 2010 * Author: mike * for use in Yale course CPSC 427a, Fall 2010 */ #pragma once #include "params.hpp" // ------------------------------------------------------------------ class Player { protected: const Algorithm alg; int choice; // player's choice register public: Player(Algorithm alg) : alg(alg), choice(0) { } virtual ~Player() { } virtual void receive(int msg)=0; int getChoice() const { return choice; } void setPreference(int preference) { choice = preference; } }; // ------------------------------------------------------------------ class FicklePlayer: public Player { private: public: FicklePlayer() : Player(fickleAlg) { } ~FicklePlayer() { } void receive(int msg) { choice = msg; } }; // ------------------------------------------------------------------ class CrowdPlayer: public Player { private: int lastMsg; // last message received public: CrowdPlayer() : Player(crowdAlg), lastMsg(0) { } ~CrowdPlayer() { } void receive(int msg) { if (msg == lastMsg) choice = msg; lastMsg = msg; } };