@@ -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;
0 commit comments