Skip to content

Commit

Permalink
redirect noninteractive ai test info from std::cout to log channel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbeck88 committed May 8, 2014
1 parent 9df86d5 commit 40a1e7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/ai/testing/ca_testing_recruitment.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1086,11 +1090,11 @@ void testing_recruitment_phase::do_recruit(int max_units_to_recruit, double qual
std::vector<potential_recruit> 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());
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions src/play_controller.cpp
Expand Up @@ -55,6 +55,10 @@

#include <boost/foreach.hpp>

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

Expand Down
10 changes: 7 additions & 3 deletions src/playsingle_controller.cpp
Expand Up @@ -51,6 +51,10 @@

#include <boost/foreach.hpp>

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)
Expand Down Expand Up @@ -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_)
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 40a1e7d

Please sign in to comment.