Skip to content

SILENT flag #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions environment/core/Halite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ GameStatistics Halite::runGame(std::vector<std::string> * 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<bool> newResult = processNextFrame(result);
//Add to vector of players that should be dead.
Expand Down Expand Up @@ -371,15 +371,18 @@ GameStatistics Halite::runGame(std::vector<std::string> * names_, unsigned int s
stats.timeout_log_filenames = std::vector<std::string>(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);
}
catch(std::runtime_error & e) {
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++) {
Expand Down
1 change: 1 addition & 0 deletions environment/core/Halite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../networking/Networking.hpp"

extern bool quiet_output;
extern bool silent_output;

struct PlayerStatistics {
int tag;
Expand Down
16 changes: 11 additions & 5 deletions environment/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ template<> struct ArgTraits< std::pair<signed int, signed int> > {
}

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();
Expand All @@ -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);

Expand All @@ -65,6 +67,8 @@ int main(int argc, char ** argv) {
else seed = (std::chrono::duration_cast<std::chrono::microseconds>(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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions environment/networking/Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
}
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions environment/networking/Networking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../core/hlt.hpp"

extern bool quiet_output;
extern bool silent_output;

class Networking {
public:
Expand Down