From 40a1e7d3fa74d59e7bba2d23fc535d9aa0a7f499 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Thu, 8 May 2014 16:00:08 -0400 Subject: [PATCH] redirect noninteractive ai test info from std::cout to log channel I named the log channel "aitesting" and in three files, playcontroller.cpp, play_singlecontroller.cpp, ca_testing_recruitment.cpp, bound this to "LOG_AIT" and substituted where I saw std::cout. This macro could be redefined to std::cout to restore previous behavior. Feel free to rename the channel if you don't like this name. The reason I made this change is so that this info does not appear when we are running noninteractive unit tests. --- src/ai/testing/ca_testing_recruitment.cpp | 16 ++++++++++------ src/play_controller.cpp | 10 +++++++--- src/playsingle_controller.cpp | 10 +++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/ai/testing/ca_testing_recruitment.cpp b/src/ai/testing/ca_testing_recruitment.cpp index 0306a73807e3..2c6622382684 100644 --- a/src/ai/testing/ca_testing_recruitment.cpp +++ b/src/ai/testing/ca_testing_recruitment.cpp @@ -45,6 +45,10 @@ namespace ai { namespace testing_ai_default { +static lg::log_domain log_aitesting("aitesting"); +#define LOG_AIT LOG_STREAM(info, log_aitesting) +//If necessary, this define can be replaced with `#define LOG_AIT std::cout` to restore previous behavior + static lg::log_domain log_ai_ca_testing_recruitment("ai/ca/testing_recruitment"); #define DBG_AI LOG_STREAM(debug, log_ai_ca_testing_recruitment) #define LOG_AI LOG_STREAM(info, log_ai_ca_testing_recruitment) @@ -764,14 +768,14 @@ static void get_recruit_quality(potential_recruit &rec, fake_team &t, std::vecto double tmpscore =(compare_unit_types(defender, pair->enemy) / ((defender_enemies != 0) ? defender_enemies : 1 )); if(tmpscore > 0){ pair->score += tmpscore; - std::cout << defender->type_name() << " resistance against " << pair->enemy->type_name() << " is: " << tmpscore << ", new score = " << pair->score << std::endl; + LOG_AIT << defender->type_name() << " resistance against " << pair->enemy->type_name() << " is: " << tmpscore << ", new score = " << pair->score << std::endl; } } if(pair->score > max_score) max_score = pair->score; if(pair->score < min_score) min_score = pair->score; - std::cout << pair->enemy->id << " resistance = " << pair->score << std::endl; + LOG_AIT << pair->enemy->id << " resistance = " << pair->score << std::endl; //} } double score = 0; @@ -1086,11 +1090,11 @@ void testing_recruitment_phase::do_recruit(int max_units_to_recruit, double qual std::vector recruit_result = ai_choose_best_recruits(*ai_t, 1, quality_factor,false); if(recruit_result.empty()) { - std::cout << "recruit_result = empty" << std::endl; + LOG_AIT << "recruit_result = empty" << std::endl; break; } const potential_recruit &recruit_unit = recruit_result[0]; - std::cout << "recruit: " << recruit_unit.id() << std::endl; + LOG_AIT << "recruit: " << recruit_unit.id() << std::endl; if(ai_t->gold() >= recruit_unit.cost()) { recruit_result_ptr recruit_action = check_recruit_action(recruit_unit.id()); @@ -1106,7 +1110,7 @@ void testing_recruitment_phase::do_recruit(int max_units_to_recruit, double qual } else { - std::cout << "gold not ok" << std::endl; + LOG_AIT << "gold not ok" << std::endl; } } } @@ -1136,7 +1140,7 @@ return 0; void testing_recruitment_phase::execute() { - std::cout << "execute floris' recruitment algorithm" << std::endl; + LOG_AIT << "execute floris' recruitment algorithm" << std::endl; int max_units_to_recruit = 1; double quality_factor = 1.0; do_recruit(max_units_to_recruit, quality_factor); diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 246856d51156..646e287073f8 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -55,6 +55,10 @@ #include +static lg::log_domain log_aitesting("aitesting"); +#define LOG_AIT LOG_STREAM(info, log_aitesting) +//If necessary, this define can be replaced with `#define LOG_AIT std::cout` to restore previous behavior + static lg::log_domain log_engine("engine"); #define LOG_NG LOG_STREAM(info, log_engine) #define DBG_NG LOG_STREAM(debug, log_engine) @@ -1452,13 +1456,13 @@ void play_controller::check_victory() } if (non_interactive()) { - std::cout << "winner: "; + LOG_AIT << "winner: "; BOOST_FOREACH(unsigned l, not_defeated) { std::string ai = ai::manager::get_active_ai_identifier_for_side(l); if (ai.empty()) ai = "default ai"; - std::cout << l << " (using " << ai << ") "; + LOG_AIT << l << " (using " << ai << ") "; } - std::cout << '\n'; + LOG_AIT << '\n'; ai_testing::log_victory(not_defeated); } diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 53441556b1ca..97b5244f0c7c 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -51,6 +51,10 @@ #include +static lg::log_domain log_aitesting("aitesting"); +#define LOG_AIT LOG_STREAM(info, log_aitesting) +//If necessary, this define can be replaced with `#define LOG_AIT std::cout` to restore previous behavior + static lg::log_domain log_engine("engine"); #define ERR_NG LOG_STREAM(err, log_engine) #define LOG_NG LOG_STREAM(info, log_engine) @@ -597,7 +601,7 @@ void playsingle_controller::play_turn(bool save) LOG_NG << "turn: " << turn() << "\n"; if(non_interactive()) - std::cout << "Turn " << turn() << ":" << std::endl; + LOG_AIT << "Turn " << turn() << ":" << std::endl; for (player_number_ = first_player_; player_number_ <= int(teams_.size()); ++player_number_) @@ -638,7 +642,7 @@ void playsingle_controller::play_turn(bool save) finish_side_turn(); if(non_interactive()) { - std::cout << " Player " << player_number_ << ": " << + LOG_AIT << " Player " << player_number_ << ": " << current_team().villages().size() << " Villages" << std::endl; ai_testing::log_turn_end(player_number_); @@ -987,7 +991,7 @@ void playsingle_controller::check_time_over(){ } if(non_interactive()) { - std::cout << "time over (draw)\n"; + LOG_AIT << "time over (draw)\n"; ai_testing::log_draw(); }