Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "stage_fallback.hpp"
00022
00023 #include "../configuration.hpp"
00024 #include "../manager.hpp"
00025 #include "../composite/ai.hpp"
00026 #include "../../foreach.hpp"
00027 #include "../../log.hpp"
00028
00029 namespace ai {
00030
00031 namespace testing_ai_default {
00032
00033 static lg::log_domain log_ai_testing_stage_fallback("ai/stage/fallback");
00034 #define DBG_AI_TESTING_STAGE_FALLBACK LOG_STREAM(debug, log_ai_testing_stage_fallback)
00035 #define LOG_AI_TESTING_STAGE_FALLBACK LOG_STREAM(info, log_ai_testing_stage_fallback)
00036 #define ERR_AI_TESTING_STAGE_FALLBACK LOG_STREAM(err, log_ai_testing_stage_fallback)
00037
00038 fallback_to_other_ai::fallback_to_other_ai( ai_context &context, const config &cfg )
00039 : stage(context,cfg), cfg_(cfg), fallback_ai_()
00040 {
00041 }
00042
00043 void fallback_to_other_ai::on_create()
00044 {
00045 config ai_cfg = cfg_.child_or_empty("ai");
00046
00047 std::string ai_algorithm = ai_cfg["ai_algorithm"];
00048 if ((ai_algorithm.empty()) || (ai_algorithm=="default_ai")) {
00049 if (configuration::parse_side_config(get_side(),cfg_,ai_cfg)) {
00050 fallback_ai_ = manager::create_transient_ai("", ai_cfg, this);
00051 }
00052 }
00053
00054 }
00055
00056
00057 config fallback_to_other_ai::to_config() const
00058 {
00059 config cfg = stage::to_config();
00060
00061 if (fallback_ai_) {
00062 cfg.add_child("ai",fallback_ai_->to_config());
00063 }
00064 return cfg;
00065 }
00066
00067 bool fallback_to_other_ai::do_play_stage()
00068 {
00069 if (fallback_ai_) {
00070 LOG_AI_TESTING_STAGE_FALLBACK << "side "<<get_side()<<" : falling back to "<<fallback_ai_->describe_self()<<std::endl;
00071 fallback_ai_->new_turn();
00072 fallback_ai_->play_turn();
00073 } else {
00074 ERR_AI_TESTING_STAGE_FALLBACK << "side "<<get_side()<<" : UNABLE TO FALLBACK, fallback ai is NULL"<<std::endl;
00075 }
00076 return false;
00077 }
00078
00079 fallback_to_other_ai::~fallback_to_other_ai()
00080 {
00081 }
00082
00083 }
00084
00085 }