本文整理汇总了C++中Country::getArmies方法的典型用法代码示例。如果您正苦于以下问题:C++ Country::getArmies方法的具体用法?C++ Country::getArmies怎么用?C++ Country::getArmies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Country
的用法示例。
在下文中一共展示了Country::getArmies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: takeAction
/**
* @brief A signal sent to the Strategy class from the game driver to indicate
* that a computer-controlled player should made their move.
*
* The AI strategy implementations override each of the fooPhase() methods
* which return the name(s) of the country or countries to act upon.
*
* Empty string indicates the AI wishes to make no move, or there are none
* possible.
*/
void Strategy::takeAction(Mode mode) {
RiskMap* map = this->driver->getRiskMap();
if (mode == REINFORCEMENT) {
std::string countryName = this->reinforcePhase();
if (countryName == "") {
return;
}
Country* country = map->getCountry(countryName);
Player* player = map->getPlayer(country->getPlayer());
this->driver->reinforceCountry(player, country, player->getReinforcements());
}
else if (mode == ATTACK) {
std::pair<std::string, std::string> countryNames = this->attackPhase();
if (countryNames.first == "" || countryNames.second == "") {
return;
}
driver->attackCountry(map->getCountry(countryNames.first), map->getCountry(countryNames.second));
}
else if (mode == FORTIFICATION) {
std::pair<std::string, std::string> countryNames = this->fortifyPhase();
if (countryNames.first == "" || countryNames.second == "") {
return;
}
// Given the two countries, fortify so that the armies are as equal as possible.
Country* origin = map->getCountry(countryNames.first);
Country* destination = map->getCountry(countryNames.second);
int splitDifference = std::abs(origin->getArmies() - destination->getArmies()) / 2;
this->driver->fortifyCountry(origin, destination, splitDifference);
}
}
示例2:
/**
* @brief Attack phase decision making
*/
std::pair<std::string, std::string> Defensive::attackPhase() {
RiskMap* map = this->driver->getRiskMap();
std::string playerName = this->driver->getCurrentPlayerName();
std::set<std::string> countriesOwnedByPlayer = map->getCountriesOwnedByPlayer(playerName);
std::pair<std::string, std::string> maxDifferencePair;
int maxDifference = 0;
for (const std::string &countryName : countriesOwnedByPlayer) {
Country* country = map->getCountry(countryName);
// Check if we have more armies than all of the neighbours opponents own
bool moreArmiesThanNeighbours = true;
for (const std::string &neighnourName : map->getNeighbours(country->getName())) {
Country* neighbour = map->getCountry(neighnourName);
if (neighbour->getPlayer() != playerName && neighbour->getArmies() > country->getArmies()) {
moreArmiesThanNeighbours = false;
break;
}
}
// If we do, find the pair of countries with the greatest chance for success
for (const std::string &neighnourName : map->getNeighbours(country->getName())) {
Country* neighbour = map->getCountry(neighnourName);
if (neighbour->getPlayer() != playerName) {
int difference = neighbour->getArmies() - country->getArmies();
if (difference >= maxDifference) {
maxDifference = difference;
maxDifferencePair = std::pair<std::string, std::string>(country->getName(), neighbour->getName());
}
}
}
}
return maxDifferencePair;
}
示例3: reinforcePhase
/**
* @brief Reinforcement phase decision making. Places all reinforcements on the
* country with the fewest armies.
*/
std::string Strategy::reinforcePhase() {
RiskMap* map = this->driver->getRiskMap();
std::string playerName = this->driver->getCurrentPlayerName();
int minArmies = 10000;
Country* minArmiesCountry = nullptr;
// add the reinforcements to the player
int numCardsSelected = map->getPlayer(playerName)->getCards();
int armiesEarned = convertCardsToReinforcements(numCardsSelected);
if (armiesEarned > 0) {
this->driver->addCardsTradeReinforcements(armiesEarned);
this->driver->updatePlayerCards(-numCardsSelected);
}
// Reinforce the weakest country
for (const std::string countryName : map->getCountriesOwnedByPlayer(playerName)) {
Country* country = map->getCountry(countryName);
int armies = country->getArmies();
if (armies < minArmies) {
minArmies = armies;
minArmiesCountry = country;
}
}
if (minArmiesCountry == nullptr) {
return "";
}
return minArmiesCountry->getName();
}