void MainScreen::allocateArmiesByNumberOfPlayers(const std::string playerName){ RiskMap* map = this->driver->getRiskMap(); const int armiesByNumPlayers[] = {40, 35, 30, 25, 20}; int totalArmies = armiesByNumPlayers[map->getPlayers().size()-2]; // Create a vector of country pointers for countries the player owns std::vector<Country*> playerCountries; for (auto const &countryName : map->getCountriesOwnedByPlayer(playerName)) { playerCountries.push_back(map->getCountry(countryName)); } // Randomize order of country pointer list auto engine = std::default_random_engine{}; std::shuffle(std::begin(playerCountries), std::end(playerCountries), engine); auto playerCountriesIter = playerCountries.begin(); while (totalArmies > 0) { Country* country = *playerCountriesIter; country->addArmies(1); totalArmies--; std::advance(playerCountriesIter, 1); if (playerCountriesIter == playerCountries.end()) { playerCountriesIter = playerCountries.begin(); } } // Signal to update the info widgets. for (auto &ent1: map->getPlayers()){ map->getPlayer(ent1.first)->notifyObservers(); } }
void GameSaveInstance::addArmiesAndPlayersToMap(World * map) { // Go through the map, assign players to countries they control and set the number of armies for (unsigned i = 0; i < countryInfos.size(); i++) { Country* country = map->getCountryFromName(countryInfos[i]->countryName.c_str()); if (country == NULL) { setError(true, "Could not find saved country on map"); return; } country->setControllingPlayer(getPlayerByName(countryInfos[i]->owningPlayer)); country->addArmies(countryInfos[i]->numArmies); } }