8 #include <boost/algorithm/string/trim.hpp>
9 #include <boost/foreach.hpp>
10 #include <boost/format.hpp>
11 #include <boost/multi_array.hpp>
12 #include <boost/program_options.hpp>
40 return 1.0*wins/(wins+losses);
45 return (wins + losses) == 0;
51 out << boost::format(
"%5.3f (#wins=%6d, #losses=%6d)")
61 typedef boost::multi_array<unsigned int, 3>
array_t;
67 :
winloss(boost::extents[MAX_DEPTH][MAX_LEVEL][2]),
68 top_level(0), top_depth(0)
72 const unsigned int level,
75 assert(depth < MAX_DEPTH);
76 assert(level < MAX_LEVEL);
82 top_level =
std::max(top_level, level);
83 top_depth =
std::max(top_depth, depth);
86 bool printAtDepth(std::ostream&
out,
const unsigned int depth)
const;
87 void printByLevel(std::ostream&
out)
const;
88 void printByDepth(std::ostream&
out)
const;
89 void showLevels(std::ostream&
out,
90 std::vector<WinLoss>& vector)
const;
94 std::vector<WinLoss>& vector)
const
97 std::vector<WinLoss>::reverse_iterator empty = vector.rbegin();
98 for (; empty != vector.rend(); ++empty) {
99 if (!empty->isEmpty())
102 vector.erase(empty.base(), vector.end());
104 unsigned int level = 1;
105 BOOST_FOREACH(
const WinLoss& wl, vector) {
106 out << boost::format(
"%2d: %s\n") % level++ % wl;
111 const unsigned int depth)
const
113 std::vector<WinLoss> vector;
114 for(
unsigned int level=0; level < MAX_LEVEL; ++level) {
118 vector.push_back(wl);
121 showLevels(out, vector);
122 return vector.empty();
128 out << boost::format(
"\n>> Depth %2d\n") %
depth;
129 printAtDepth(out,
depth);
135 std::vector<WinLoss> vector;
136 for(
unsigned int level=0; level < MAX_LEVEL; ++level) {
142 vector.push_back(wl);
145 showLevels(out, vector);
160 const vector<Move>&
moves)
162 std::ifstream in(csa_file.c_str());
165 std::cerr <<
"File not found: " << csa_file <<
"\n";
171 while (std::getline(in, line))
173 if (line.find(
"%TORYO") != std::string::npos)
197 unsigned int depth = 1;
199 BOOST_FOREACH(
const Move& move, moves) {
201 book.
getMoves(stateIndex, (player == turn ?
false :
true));
202 std::sort(wmoves.begin(), wmoves.end(),
208 osl::record::opening::WeightedBook::WMoveContainer::iterator found =
210 for (; found != wmoves.end(); ++found) {
211 if (found->getMove() == move)
214 if (found == wmoves.end())
220 if (turn == player) {
221 const unsigned int level = std::distance(wmoves.begin(), found);
230 stateIndex = found->getStateIndex();
236 const std::string& csa_file,
247 if (duplicates.
regist(moves))
255 if (black.find(player_name) != std::string::npos) {
259 else if (white.find(player_name) != std::string::npos) {
264 std::cerr <<
"Ignore this play: " << csa_file <<
"\n";
272 int main(
int argc,
char **argv)
274 std::string player_name;
276 boost::program_options::options_description command_line_options;
277 command_line_options.add_options()
278 (
"input-file", boost::program_options::value<std::vector<std::string> >(),
279 "input files in the CSA format")
280 (
"player", boost::program_options::value<std::string>(&player_name)->default_value(
"gps"),
281 "input files in the CSA format")
282 (
"help",
"Show help message");
283 boost::program_options::variables_map
vm;
284 boost::program_options::positional_options_description p;
285 p.add(
"input-file", -1);
290 boost::program_options::command_line_parser(
291 argc, argv).options(command_line_options).positional(p).
run(), vm);
292 boost::program_options::notify(vm);
293 if (vm.count(
"help"))
295 std::cerr <<
"Usage: " << argv[0] <<
" [options] csa-file [...]\n";
296 std::cerr <<
" " << argv[0] <<
" [options]\n";
297 std::cout << command_line_options << std::endl;
301 catch (std::exception &e)
303 std::cerr <<
"error in parsing options" << std::endl
304 << e.what() << std::endl;
305 std::cerr <<
"Usage: " << argv[0] <<
" [options] csa-file [...]\n";
306 std::cerr <<
" " << argv[0] <<
" [options]\n";
307 std::cerr << command_line_options << std::endl;
311 std::vector<std::string>
files;
312 if (vm.count(
"input-file"))
314 const std::vector<std::string> temp = vm[
"input-file"].as<std::vector<std::string> >();
315 files.insert(files.end(), temp.begin(), temp.end());
320 while(std::getline(std::cin , line))
322 boost::algorithm::trim(line);
323 files.push_back(line);
329 BOOST_FOREACH(
const std::string& file, files)
331 readFile(player_name, file, check_duplicate);
337 std::locale::global(std::locale(
""));
338 check_duplicate.
print(std::cout);