Skip to content

Commit 99229ac

Browse files
committed
Merge branch 'single_player_mode'
2 parents d8e2fb7 + c0fba2d commit 99229ac

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

environment/core/Halite.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Halite::Halite(unsigned short width_, unsigned short height_, unsigned int seed_
226226
ignore_timeout = shouldIgnoreTimeout;
227227

228228
//Init statistics
229+
productive_squares_remaining = 1; // just more than zero to get through the game_loop the first time
229230
alive_frame_count = std::vector<unsigned short>(number_of_players, 1);
230231
last_territory_count = std::vector<unsigned int>(number_of_players, 1);
231232
full_territory_count = std::vector<unsigned int>(number_of_players, 1);
@@ -325,7 +326,7 @@ GameStatistics Halite::runGame(std::vector<std::string> * names_, unsigned int s
325326
for(auto a = names_->begin(); a != names_->end(); a++) player_names.push_back(a->substr(0, 30));
326327
}
327328
const int maxTurnNumber = sqrt(game_map.map_width * game_map.map_height) * 10;
328-
while(std::count(result.begin(), result.end(), true) > 1 && turn_number < maxTurnNumber) {
329+
while(turn_number < maxTurnNumber && (std::count(result.begin(), result.end(), true) > 1 || (number_of_players == 1 && productive_squares_remaining > 0))) {
329330
//Increment turn number:
330331
turn_number++;
331332
if(!quiet_output) std::cout << "Turn " << turn_number << "\n";
@@ -342,6 +343,10 @@ GameStatistics Halite::runGame(std::vector<std::string> * names_, unsigned int s
342343
return last_territory_count[u1] < last_territory_count[u2];
343344
});
344345
for(auto a = newRankings.begin(); a != newRankings.end(); a++) rankings.push_back(*a);
346+
347+
//Count productive squares remaining for Halite single-player game
348+
productive_squares_remaining = 0;
349+
for(unsigned short b = 0; b < game_map.map_height; b++) for(unsigned short c = 0; c < game_map.map_width; c++) if(game_map.contents[b][c].owner == 0 && game_map.contents[b][c].production > 0) productive_squares_remaining++;
345350
result = newResult;
346351
}
347352
std::vector<unsigned int> newRankings;

environment/core/Halite.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Halite {
5555
//Game state
5656
unsigned short turn_number;
5757
unsigned short number_of_players;
58+
unsigned short productive_squares_remaining;
5859
bool ignore_timeout;
5960
hlt::Map game_map;
6061
std::vector<std::string> player_names;

environment/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int main(int argc, char ** argv) {
102102
}
103103
}
104104
else {
105-
if(unlabeledArgs.size() < 2) {
105+
if(unlabeledArgs.size() < 1) {
106106
std::cout << "Invalid player parameters from argv. Prompting instead:" << std::endl;
107107
networking = promptNetworking();
108108
}
@@ -144,7 +144,7 @@ Networking promptNetworking() {
144144
bool done = false;
145145
for(int np = 0; !done; np++) {
146146
//If less than 2, bypass this step: Ask if the user like to add another AI
147-
if (np >= 2) {
147+
if (np >= 1) {
148148
std::cout << "Would you like to add another player? Please enter Yes or No: ";
149149
while (true) {
150150
std::getline(std::cin, in);

0 commit comments

Comments
 (0)