Author: crab
Date: Thu Apr 30 18:35:04 2009
New Revision: 35351

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35351&view=rev
Log:
Improved ai/testing logging to log per-turn information about gold, villages, 
and units

Modified:
    trunk/src/actions.cpp
    trunk/src/ai/testing.cpp
    trunk/src/ai/testing.hpp
    trunk/src/playsingle_controller.cpp

Modified: trunk/src/actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=35351&r1=35350&r2=35351&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Thu Apr 30 18:35:04 2009
@@ -1913,7 +1913,7 @@
 
 void check_victory(const gamestatus& status, unit_map& units, 
std::vector<team>& teams, display& disp)
 {
-       std::vector<int> seen_leaders;
+       std::vector<unsigned int> seen_leaders;
        for(unit_map::const_iterator i = units.begin();
                        i != units.end(); ++i) {
                if(i->second.can_recruit()) {
@@ -1964,25 +1964,13 @@
 
                if(non_interactive()) {
                        std::cout << "winner: ";
-                       for(std::vector<int>::const_iterator i = 
seen_leaders.begin(); i != seen_leaders.end(); ++i) {
+                       for(std::vector<unsigned int>::const_iterator i = 
seen_leaders.begin(); i != seen_leaders.end(); ++i) {
                                std::string ai = teams[*i - 1].ai_algorithm();
                                if (ai == "") ai = "default ai";
                                std::cout << *i << " (using " << ai << ") ";
                        }
                        std::cout << "\n";
-                       ai_testing::log_victory();
-                       //@todo 1.7 remove this code, as it will be in 
log_victory
-                       for(std::vector<int>::const_iterator i = 
seen_leaders.begin(); i != seen_leaders.end(); ++i) {
-                               LOG_AI_TESTING << "WINNER: "<< *i <<std::endl;
-                       }
-                       LOG_AI_TESTING << "VICTORY_TURN: "<< status.turn() 
<<std::endl;
-                       for (std::vector<team>::const_iterator tm = 
teams.begin(); tm != teams.end(); ++tm) {
-                               int side = tm-teams.begin()+1;
-                               LOG_AI_TESTING << "AI_IDENTIFIER"<<side<<": " 
<< tm->ai_algorithm_identifier() <<std::endl;
-                               LOG_AI_TESTING << "FACTION"<<side<<": " << 
tm->name() << std::endl;
-                       }
-                       LOG_AI_TESTING << "VERSION: " << game_config::revision 
<< std::endl;
-
+                       ai_testing::log_victory(seen_leaders);
                }
 
                LOG_NG << "throwing end level exception...\n";

Modified: trunk/src/ai/testing.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/testing.cpp?rev=35351&r1=35350&r2=35351&view=diff
==============================================================================
--- trunk/src/ai/testing.cpp (original)
+++ trunk/src/ai/testing.cpp Thu Apr 30 18:35:04 2009
@@ -16,6 +16,8 @@
  * Gather statistics important for AI testing and output them
  * @file ai/testing.cpp
  */
+#include "ai_interface.hpp"
+#include "ai_manager.hpp"
 #include "testing.hpp"
 #include "../log.hpp"
 
@@ -24,30 +26,61 @@
 #define LOG_AI_TESTING LOG_STREAM(info, log_ai_testing)
 #define ERR_AI_TESTING LOG_STREAM(err, log_ai_testing)
 
-void ai_testing::log_turn_start()
+void ai_testing::log_turn_start(unsigned int side)
 {
+       log_turn("TURN_START",side);
+}
+
+void ai_testing::log_turn_end(unsigned int side)
+{
+       log_turn("TURN_END",side);
+}
+
+void ai_testing::log_turn(const char* msg, unsigned int side)
+{
+       ai_interface::info& i = ai_manager::get_ai_info();
+       assert(side>=1);
+       team& current_team = i.teams[side-1];
+
+       size_t _turn_number = i.state.turn();
+       int _units = team_units(i.units,side);
+       int _units_cost = team_units_cost(i.units,side);
+       int _gold = current_team.gold();
+       int _villages = current_team.villages().size();
+       int _income = current_team.total_income();
+
+       LOG_AI_TESTING << msg <<                  side << ": " << _turn_number 
<< std::endl;
+       LOG_AI_TESTING << msg << "_UNITS"      << side << ": " << _units << 
std::endl;
+       LOG_AI_TESTING << msg << "_UNITS_COST" << side << ": " << _units_cost 
<< std::endl;
+       LOG_AI_TESTING << msg << "_GOLD"       << side << ": " << _gold << 
std::endl;
+       LOG_AI_TESTING << msg << "_VILLAGES"   << side << ": " << _villages << 
std::endl;
+       LOG_AI_TESTING << msg << "_INCOME"     << side << ": " << _income << 
std::endl;
 }
 
 void ai_testing::log_draw()
 {
+       LOG_AI_TESTING << "DRAW:" << std::endl;
 }
 
-void ai_testing::log_victory()
+void ai_testing::log_victory(std::vector<unsigned int> winners)
 {
-/*
-       for(std::vector<int>::const_iterator i = seen_leaders.begin(); i != 
seen_leaders.end(); ++i) {
-               LOG_AI_TESTING << "WINNER: "<< *i <<std::endl;
+       for(std::vector<unsigned int>::const_iterator w = winners.begin(); w != 
winners.end(); ++w) {
+               LOG_AI_TESTING << "WINNER: "<< *w <<std::endl;
        }
-       LOG_AI_TESTING << "VICTORY_TURN: "<< status.turn() <<std::endl;
-       for (std::vector<team>::const_iterator tm = teams.begin(); tm != 
teams.end(); ++tm) {
-               int side = tm-teams.begin()+1;
+}
+
+void ai_testing::log_game_start()
+{
+       ai_interface::info& i = ai_manager::get_ai_info();
+       for (std::vector<team>::const_iterator tm = i.teams.begin(); tm != 
i.teams.end(); ++tm) {
+               int side = tm-i.teams.begin()+1;
                LOG_AI_TESTING << "AI_IDENTIFIER"<<side<<": " << 
tm->ai_algorithm_identifier() <<std::endl;
                LOG_AI_TESTING << "FACTION"<<side<<": " << tm->name() << 
std::endl;
        }
        LOG_AI_TESTING << "VERSION: " << game_config::revision << std::endl;
-*/
 }
 
-void ai_testing::log_unknown_error_while_playing_level()
+void ai_testing::log_game_end()
 {
+       LOG_AI_TESTING << "GAME_END_TURN: "<< 
ai_manager::get_ai_info().state.turn() <<std::endl;
 }

Modified: trunk/src/ai/testing.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/testing.hpp?rev=35351&r1=35350&r2=35351&view=diff
==============================================================================
--- trunk/src/ai/testing.hpp (original)
+++ trunk/src/ai/testing.hpp Thu Apr 30 18:35:04 2009
@@ -22,13 +22,20 @@
 
 #include "../global.hpp"
 
+#include <vector>
+
 class ai_testing{
 public:
        /*
         * Log at start of the turn
        */
-       static void log_turn_start();
+       static void log_turn_start( unsigned int side );
 
+
+       /*
+        * Log at end of the turn
+       */
+       static void log_turn_end( unsigned int side );
 
        /*
         * Log in case of draw
@@ -38,14 +45,26 @@
        
        /*
         * Log in case of victory
+        * teams vector of winner teams
         */
-       static void log_victory();
+       static void log_victory( std::vector<unsigned int> teams );
 
 
        /*
-        * Log in case of unknown error while playing level
+        * Log at game start
         */
-       static void log_unknown_error_while_playing_level();
+       static void log_game_start();
+
+
+       /*
+        * Log at game end
+        */
+       static void log_game_end();
+
+protected:
+
+       static void log_turn( const char *msg, unsigned int side );
+
 };
 
 #endif

Modified: trunk/src/playsingle_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playsingle_controller.cpp?rev=35351&r1=35350&r2=35351&view=diff
==============================================================================
--- trunk/src/playsingle_controller.cpp (original)
+++ trunk/src/playsingle_controller.cpp Thu Apr 30 18:35:04 2009
@@ -322,6 +322,7 @@
                // Avoid autosaving after loading, but still
                // allow the first turn to have an autosave.
                bool save = !loading_game_;
+               ai_testing::log_game_start();
                for(; ; first_player_ = 1) {
                        play_turn(save);
                        save = true;
@@ -332,6 +333,7 @@
                log.quit(status_.turn());
                throw;
        } catch(end_level_exception& end_level) {
+               ai_testing::log_game_end();
                *end_level_result = end_level;
                if(!end_level.custom_endlevel_music.empty()) {
                        switch(end_level.result) {
@@ -572,6 +574,7 @@
                                turn_data.sync_network();
                                continue;
                        }
+                       ai_testing::log_turn_start(player_number_);
                        play_side(player_number_, save);
                }
 
@@ -581,7 +584,7 @@
                        std::cout << " Player " << player_number_ << ": " <<
                                current_team().villages().size() << " Villages" 
<<
                                std::endl;
-                       ai_testing::log_turn_start();
+                       ai_testing::log_turn_end(player_number_);
                }
 
                check_victory(status_, units_, teams_, *gui_);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to