#include "riskConstants.h" #include "demoPlayer.h" #include "game.h" #include "player.h" #include "game.h" class LabPlayer1 : public Player { private: int countryToAttack; int countryToAttackFrom; public: void doAllocation(int newArmies) { Country countries[MAXCOUNTRY]; int countryCount = theGame->getCountries(countries); int me = theGame->getPlayerID(this); // place armies randomly Country myCountries[MAXCOUNTRY]; int myCountryCount = 0; // copy all of my countries into separate array for (int c = 0; c < countryCount; c++) { if (countries[c].getPlayer() == me) { myCountries[myCountryCount] = countries[c]; myCountryCount++; } } // randomly choose one int randCountry = rand() % myCountryCount; theGame->doAllocation(myCountries[randCountry].getID(),newArmies); } bool doAttack() { Country countries[MAXCOUNTRY]; int countryCount = theGame->getCountries(countries); // find an opponent and attack int me = theGame->getPlayerID(this); for (int c = 0; c < countryCount; c++) { if (countries[c].getPlayer() == me) { // now look for possible opponent for (int v = 0; v < countryCount; v++) { if (theGame->areAdjacent(countries[c].getID(), countries[v].getID()) && countries[v].getPlayer() != me) { theGame->attack(countries[c].getID(),countries[v].getID()); return false; } } } } return false; } };