ai/testing/ca_global_fallback.cpp

Go to the documentation of this file.
00001 /* $Id: ca_global_fallback.cpp 53726 2012-03-31 18:16:27Z fendrin $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Yurii Chernyi <terraninfo@terraninfo.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  * @file
00018  * Defensive fallback, to be used during unfavourable conditions
00019  */
00020 
00021 #include "ca_global_fallback.hpp"
00022 
00023 #include "../composite/ai.hpp"
00024 
00025 #include "../actions.hpp"
00026 
00027 #include "../../game_display.hpp"
00028 #include "../../foreach.hpp"
00029 #include "../../log.hpp"
00030 #include "../../map.hpp"
00031 #include "../../map_label.hpp"
00032 #include "../../replay.hpp"
00033 #include "../../resources.hpp"
00034 #include "../../sdl_utils.hpp"
00035 #include "../../team.hpp"
00036 #include "../../terrain_filter.hpp"
00037 #include "../../tod_manager.hpp"
00038 
00039 
00040 namespace ai {
00041 
00042 namespace testing_ai_default {
00043 
00044 static lg::log_domain log_ai_testing_ca_global_fallback("ai/ca/global_fallback");
00045 #define DBG_AI LOG_STREAM(debug, log_ai_testing_ca_global_fallback)
00046 #define LOG_AI LOG_STREAM(info, log_ai_testing_ca_global_fallback)
00047 #define WRN_AI LOG_STREAM(warn, log_ai_testing_ca_global_fallback)
00048 #define ERR_AI LOG_STREAM(err, log_ai_testing_ca_global_fallback)
00049 
00050 //==================================
00051 // aux utils
00052 //
00053 
00054 static void display_label(int /*side*/, const map_location& location, const std::string& text, bool surrounded)
00055 {
00056     display* gui = display::get_singleton();
00057     std::string team_name;
00058 
00059     SDL_Color color = int_to_color(team::get_side_rgb(surrounded ? 2 : 1 ) );//@fixme: for tests
00060 
00061     const terrain_label *res;
00062     res = gui->labels().set_label(location, text, team_name, color);
00063     if (res)
00064         recorder.add_label(res);
00065 }
00066 
00067 
00068 //==================================
00069 
00070 global_fallback_phase::global_fallback_phase( rca_context &context, const config &cfg )
00071     : candidate_action(context,cfg)
00072 {
00073 }
00074 
00075 
00076 global_fallback_phase::~global_fallback_phase()
00077 {
00078 }
00079 
00080 
00081 double global_fallback_phase::evaluate()
00082 {
00083     return get_score();
00084 }
00085 
00086 
00087 void global_fallback_phase::execute()
00088 {
00089     LOG_AI << "start" << std::endl;
00090     const int ticks = SDL_GetTicks();
00091     double res_sum = 0;
00092     foreach( unit &u, *resources::units)
00093     {
00094         if (u.side()!=get_side())
00095         {
00096             continue;
00097         }
00098         double res = 0.1; //@todo: how badly the unit 'u' will be hurt by enemy
00099         res_sum += res;
00100         display_label(get_side(),u.get_location(),str_cast(res),false);
00101     }
00102     LOG_AI << "sum is " << res_sum << std::endl;
00103 
00104     LOG_AI << "end in [" << (SDL_GetTicks()-ticks) << "] ticks" << std::endl;
00105 }
00106 
00107 } // end of namespace testing_ai_default
00108 
00109 } // end of namespace ai
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:32 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs