-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
testing.cpp
113 lines (99 loc) · 3.98 KB
/
testing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Copyright (C) 2009 - 2014 by Yurii Chernyi <terraninfo@terraninfo.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* Gather statistics important for AI testing and output them
* @file
*/
#include "manager.hpp"
#include "testing.hpp"
#include "../log.hpp"
#include "../replay.hpp"
#include "../util.hpp"
#include "../resources.hpp"
#include "../team.hpp"
#include "../unit.hpp"
#include "../tod_manager.hpp"
static lg::log_domain log_ai_testing("ai/testing");
#define DBG_AI_TESTING LOG_STREAM(debug, log_ai_testing)
#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(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)
{
assert(side>=1);
team& current_team = (*resources::teams)[side-1];
int _turn_number = resources::tod_manager->turn();
int _units = side_units(side);
int _units_cost = side_units_cost(side);
int _gold = current_team.gold();
int _villages = current_team.villages().size();
int _income = current_team.total_income();
DBG_AI_TESTING << msg << side << ": " << _turn_number << std::endl;
DBG_AI_TESTING << msg << "_UNITS" << side << ": " << _units << std::endl;
DBG_AI_TESTING << msg << "_UNITS_COST" << side << ": " << _units_cost << std::endl;
DBG_AI_TESTING << msg << "_GOLD" << side << ": " << _gold << std::endl;
DBG_AI_TESTING << msg << "_VILLAGES" << side << ": " << _villages << std::endl;
DBG_AI_TESTING << msg << "_INCOME" << side << ": " << _income << std::endl;
config c;
c["side"] = int(side);
c["turn"] = _turn_number;
c["event"] = msg;
c["units"] = _units;
c["units_cost"] = _units_cost;
c["gold"] = _gold;
c["villages"] = _villages;
recorder.add_log_data("ai_log","turn_info",c);
}
void ai_testing::log_draw()
{
LOG_AI_TESTING << "DRAW:" << std::endl;
recorder.add_log_data("ai_log","result","draw");
}
void ai_testing::log_victory(std::set<unsigned int> winners)
{
recorder.add_log_data("ai_log","result","victory");
for(std::set<unsigned int>::const_iterator w = winners.begin(); w != winners.end(); ++w) {
LOG_AI_TESTING << "WINNER: "<< *w <<std::endl;
recorder.add_log_data("ai_log","winner",str_cast(*w));
}
}
void ai_testing::log_game_start()
{
for (std::vector<team>::const_iterator tm = resources::teams->begin(); tm != resources::teams->end(); ++tm) {
int side = tm-resources::teams->begin()+1;
LOG_AI_TESTING << "AI_IDENTIFIER"<<side<<": " << ai::manager::get_active_ai_identifier_for_side(side) <<std::endl;
LOG_AI_TESTING << "TEAM"<<side<<": " << tm->name() << std::endl;
recorder.add_log_data("ai_log","ai_id"+str_cast(side),ai::manager::get_active_ai_identifier_for_side(side));
recorder.add_log_data("ai_log","faction"+str_cast(side),tm->name());
///@todo 1.9: add information about ai_config
}
LOG_AI_TESTING << "VERSION: " << game_config::revision << std::endl;
recorder.add_log_data("ai_log","version",game_config::revision);
}
void ai_testing::log_game_end()
{
LOG_AI_TESTING << "GAME_END_TURN: "<< resources::tod_manager->turn() <<std::endl;
recorder.add_log_data("ai_log","end_turn",
str_cast(resources::tod_manager->turn()));
for (std::vector<team>::const_iterator tm = resources::teams->begin(); tm != resources::teams->end(); ++tm) {
int side = tm-resources::teams->begin()+1;
recorder.add_log_data("ai_log","end_gold"+str_cast(side),str_cast(tm->gold()));
recorder.add_log_data("ai_log","end_units"+str_cast(side),str_cast(side_units(side)));
}
}