From db9ae61be0d91df580877e51be212c706b0aebe6 Mon Sep 17 00:00:00 2001 From: haze Date: Sun, 13 Nov 2016 01:03:31 -0500 Subject: [PATCH 1/2] Added SILENT flag --- environment/core/Halite.cpp | 9 ++++++--- environment/core/Halite.hpp | 1 + environment/main.cpp | 16 +++++++++++----- environment/networking/Networking.cpp | 6 +++--- environment/networking/Networking.hpp | 1 + 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/environment/core/Halite.cpp b/environment/core/Halite.cpp index 8611f6dac..1824b90bf 100644 --- a/environment/core/Halite.cpp +++ b/environment/core/Halite.cpp @@ -328,7 +328,7 @@ GameStatistics Halite::runGame(std::vector * names_, unsigned int s while(std::count(result.begin(), result.end(), true) > 1 && turn_number < maxTurnNumber) { //Increment turn number: turn_number++; - if(!quiet_output) std::cout << "Turn " << turn_number << "\n"; + if(!quiet_output && !silent_output) std::cout << "Turn " << turn_number << "\n"; //Frame logic. std::vector newResult = processNextFrame(result); //Add to vector of players that should be dead. @@ -371,6 +371,7 @@ GameStatistics Halite::runGame(std::vector * names_, unsigned int s stats.timeout_log_filenames = std::vector(timeout_tags.size()); //Output gamefile. First try the replays folder; if that fails, just use the straight filename. stats.output_filename = "Replays/" + std::to_string(id) + '-' + std::to_string(seed) + ".hlt"; + std::cout << stats.output_filename << std::endl; try { output(stats.output_filename); } @@ -378,8 +379,10 @@ GameStatistics Halite::runGame(std::vector * names_, unsigned int s stats.output_filename = stats.output_filename.substr(8); output(stats.output_filename); } - if(!quiet_output) std::cout << "Map seed was " << seed << std::endl << "Opening a file at " << stats.output_filename << std::endl; - else std::cout << stats.output_filename << ' ' << seed << std::endl; + if(!silent_output) { + if(!quiet_output) std::cout << "Map seed was " << seed << std::endl << "Opening a file at " << stats.output_filename << std::endl; + else std::cout << stats.output_filename << ' ' << seed << std::endl; + } //Output logs for players that timed out or errored. int timeoutIndex = 0; for(auto a = timeout_tags.begin(); a != timeout_tags.end(); a++) { diff --git a/environment/core/Halite.hpp b/environment/core/Halite.hpp index 5dddfe80a..09c3baee1 100644 --- a/environment/core/Halite.hpp +++ b/environment/core/Halite.hpp @@ -15,6 +15,7 @@ #include "../networking/Networking.hpp" extern bool quiet_output; +extern bool silent_output; struct PlayerStatistics { int tag; diff --git a/environment/main.cpp b/environment/main.cpp index fc4e50a50..39a0ee5fa 100644 --- a/environment/main.cpp +++ b/environment/main.cpp @@ -23,6 +23,7 @@ template<> struct ArgTraits< std::pair > { } bool quiet_output = false; //Need to be passed to a bunch of classes; extern is cleaner. +bool silent_output = false; //Actual peace and quiet ;^) Halite * my_game; //Is a pointer to avoid problems with assignment, dynamic memory, and default constructors. Networking promptNetworking(); @@ -44,7 +45,8 @@ int main(int argc, char ** argv) { TCLAP::CmdLine cmd("Halite Game Environment", ' ', "1.0.1"); //Switch Args. - TCLAP::SwitchArg quietSwitch("q", "quiet", "Runs game in quiet mode, producing machine-parsable output.", cmd, false); + TCLAP::SwitchArg quietSwitch("m", "machine", "Produces machine output only.", cmd, false); + TCLAP::SwitchArg silentSwitch("v", "silent", "Produces no output.", cmd, false); TCLAP::SwitchArg overrideSwitch("o", "override", "Overrides player-sent names using cmd args [SERVER ONLY].", cmd, false); TCLAP::SwitchArg timeoutSwitch("t", "timeout", "Causes game environment to ignore timeouts (give all bots infinite time).", cmd, false); @@ -65,6 +67,8 @@ int main(int argc, char ** argv) { else seed = (std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() % 4294967295); quiet_output = quietSwitch.getValue(); + silent_output = silentSwitch.getValue(); + std::cout << "b4?" << std::endl; bool override_names = overrideSwitch.getValue(); bool ignore_timeout = timeoutSwitch.getValue(); @@ -126,11 +130,12 @@ int main(int argc, char ** argv) { if(names != NULL) delete names; std::string victoryOut; - if(quiet_output) { + if(!silent_output) { + if(!quiet_output) { std::cout << stats; - } - else { + } else { for(unsigned int a = 0; a < stats.player_statistics.size(); a++) std::cout << "Player #" << stats.player_statistics[a].tag << ", " << my_game->getName(stats.player_statistics[a].tag) << ", came in rank #" << stats.player_statistics[a].rank << "!\n"; + } } delete my_game; @@ -169,7 +174,8 @@ Networking promptNetworking() { } } - std::cout << "Connected to player #" << int(np + 1) << std::endl; + if(!silent_output) + std::cout << "Connected to player #" << int(np + 1) << std::endl; } return n; } diff --git a/environment/networking/Networking.cpp b/environment/networking/Networking.cpp index 549d998c6..1cd5a6658 100644 --- a/environment/networking/Networking.cpp +++ b/environment/networking/Networking.cpp @@ -315,7 +315,7 @@ int Networking::handleInitNetworking(unsigned char playerTag, const hlt::Map & m sendString(playerTag, prodString); sendString(playerTag, mapString); std::string outMessage = "Init Message sent to player " + std::to_string(int(playerTag)) + ".\n"; - if(!quiet_output) std::cout << outMessage; + if(!quiet_output && !silent_output) std::cout << outMessage; player_logs[playerTag - 1] += " --- Init ---\n"; @@ -326,7 +326,7 @@ int Networking::handleInitNetworking(unsigned char playerTag, const hlt::Map & m player_logs[playerTag - 1] += response + "\n --- Bot used " + std::to_string(millisTaken) + " milliseconds ---"; *playerName = response.substr(0, 30); - if(!quiet_output) { + if(!quiet_output && !silent_output) { std::string inMessage = "Init Message received from player " + std::to_string(int(playerTag)) + ", " + *playerName + ".\n"; std::cout << inMessage; } @@ -433,7 +433,7 @@ void Networking::killPlayer(unsigned char playerTag) { connections[playerTag - 1].write = NULL; std::string deadMessage = "Player " + std::to_string(playerTag) + " is dead\n"; - if(!quiet_output) std::cout << deadMessage; + if(!quiet_output && !silent_output) std::cout << deadMessage; #else diff --git a/environment/networking/Networking.hpp b/environment/networking/Networking.hpp index 0e50dea34..60025fb2f 100644 --- a/environment/networking/Networking.hpp +++ b/environment/networking/Networking.hpp @@ -22,6 +22,7 @@ #include "../core/hlt.hpp" extern bool quiet_output; +extern bool silent_output; class Networking { public: From 0f43f0ae3b9aa0dcc220a7f38da5857d3f6eb77f Mon Sep 17 00:00:00 2001 From: haze Date: Sun, 13 Nov 2016 01:06:20 -0500 Subject: [PATCH 2/2] fixed quiet bug --- environment/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment/main.cpp b/environment/main.cpp index 39a0ee5fa..6f7a751f8 100644 --- a/environment/main.cpp +++ b/environment/main.cpp @@ -131,7 +131,7 @@ int main(int argc, char ** argv) { std::string victoryOut; if(!silent_output) { - if(!quiet_output) { + if(quiet_output) { std::cout << stats; } else { for(unsigned int a = 0; a < stats.player_statistics.size(); a++) std::cout << "Player #" << stats.player_statistics[a].tag << ", " << my_game->getName(stats.player_statistics[a].tag) << ", came in rank #" << stats.player_statistics[a].rank << "!\n";