ai/testing.cpp

Go to the documentation of this file.
00001 /* $Id: testing.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
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  * Gather statistics important for AI testing and output them
00018  * @file
00019  */
00020 #include "manager.hpp"
00021 #include "testing.hpp"
00022 #include "../log.hpp"
00023 #include "../replay.hpp"
00024 #include "../util.hpp"
00025 #include "../resources.hpp"
00026 #include "../team.hpp"
00027 #include "../tod_manager.hpp"
00028 
00029 static lg::log_domain log_ai_testing("ai/testing");
00030 #define DBG_AI_TESTING LOG_STREAM(debug, log_ai_testing)
00031 #define LOG_AI_TESTING LOG_STREAM(info, log_ai_testing)
00032 #define ERR_AI_TESTING LOG_STREAM(err, log_ai_testing)
00033 
00034 void ai_testing::log_turn_start(unsigned int side)
00035 {
00036     log_turn("TURN_START",side);
00037 }
00038 
00039 void ai_testing::log_turn_end(unsigned int side)
00040 {
00041     log_turn("TURN_END",side);
00042 }
00043 
00044 void ai_testing::log_turn(const char* msg, unsigned int side)
00045 {
00046     assert(side>=1);
00047     team& current_team = (*resources::teams)[side-1];
00048 
00049     int _turn_number = resources::tod_manager->turn();
00050     int _units = side_units(side);
00051     int _units_cost = side_units_cost(side);
00052     int _gold = current_team.gold();
00053     int _villages = current_team.villages().size();
00054     int _income = current_team.total_income();
00055 
00056     DBG_AI_TESTING << msg <<                  side << ": " << _turn_number << std::endl;
00057     DBG_AI_TESTING << msg << "_UNITS"      << side << ": " << _units << std::endl;
00058     DBG_AI_TESTING << msg << "_UNITS_COST" << side << ": " << _units_cost << std::endl;
00059     DBG_AI_TESTING << msg << "_GOLD"       << side << ": " << _gold << std::endl;
00060     DBG_AI_TESTING << msg << "_VILLAGES"   << side << ": " << _villages << std::endl;
00061     DBG_AI_TESTING << msg << "_INCOME"     << side << ": " << _income << std::endl;
00062 
00063     config c;
00064     c["side"] = int(side);
00065     c["turn"] = _turn_number;
00066     c["event"] = msg;
00067     c["units"] = _units;
00068     c["units_cost"] = _units_cost;
00069     c["gold"] = _gold;
00070     c["villages"] = _villages;
00071     recorder.add_log_data("ai_log","turn_info",c);
00072 }
00073 
00074 void ai_testing::log_draw()
00075 {
00076     LOG_AI_TESTING << "DRAW:" << std::endl;
00077     recorder.add_log_data("ai_log","result","draw");
00078 }
00079 
00080 void ai_testing::log_victory(std::vector<unsigned int> winners)
00081 {
00082     recorder.add_log_data("ai_log","result","victory");
00083     for(std::vector<unsigned int>::const_iterator w = winners.begin(); w != winners.end(); ++w) {
00084         LOG_AI_TESTING << "WINNER: "<< *w <<std::endl;
00085         recorder.add_log_data("ai_log","winner",str_cast(*w));
00086     }
00087 }
00088 
00089 void ai_testing::log_game_start()
00090 {
00091     for (std::vector<team>::const_iterator tm = resources::teams->begin(); tm != resources::teams->end(); ++tm) {
00092         int side = tm-resources::teams->begin()+1;
00093         LOG_AI_TESTING << "AI_IDENTIFIER"<<side<<": " << ai::manager::get_active_ai_identifier_for_side(side) <<std::endl;
00094         LOG_AI_TESTING << "FACTION"<<side<<": " << tm->name() << std::endl;
00095         recorder.add_log_data("ai_log","ai_id"+str_cast(side),ai::manager::get_active_ai_identifier_for_side(side));
00096         recorder.add_log_data("ai_log","faction"+str_cast(side),tm->name());
00097         ///@todo 1.9: add information about ai_config
00098     }
00099     LOG_AI_TESTING << "VERSION: " << game_config::revision << std::endl;
00100     recorder.add_log_data("ai_log","version",game_config::revision);
00101 }
00102 
00103 void ai_testing::log_game_end()
00104 {
00105     LOG_AI_TESTING << "GAME_END_TURN: "<< resources::tod_manager->turn() <<std::endl;
00106     recorder.add_log_data("ai_log","end_turn",
00107         str_cast(resources::tod_manager->turn()));
00108     for (std::vector<team>::const_iterator tm = resources::teams->begin(); tm != resources::teams->end(); ++tm) {
00109         int side = tm-resources::teams->begin()+1;
00110         recorder.add_log_data("ai_log","end_gold"+str_cast(side),str_cast(tm->gold()));
00111         recorder.add_log_data("ai_log","end_units"+str_cast(side),str_cast(side_units(side)));
00112     }
00113 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:44 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs