16 #include <boost/format.hpp>
17 #include <boost/lambda/lambda.hpp>
18 #include <boost/lambda/bind.hpp>
19 #include <boost/program_options.hpp>
20 #include <boost/progress.hpp>
21 #include <boost/shared_ptr.hpp>
27 using namespace boost::lambda;
28 namespace bp = boost::program_options;
61 qsearch_t qs(core, table);
63 return qs.search(state.
turn(), ev, lastMove, 4);
68 double sum, mean, var, dev, skew, kurt;
71 std::cout << boost::format(
" total: %g\n") % src.size()
72 << boost::format(
" mean: %g\n") % mean
73 << boost::format(
" dev: %g\n") % dev;
78 const boost::program_options::options_description& command_line_options)
81 "Usage: " << argv[0] <<
" [options] <a_joseki_file.dat>\n"
82 << command_line_options
89 boost::shared_ptr<osl::record::Characters>(
93 std::cout << boost::format(
"state_index: %g\n") % state_index
97 std::cout <<
"\nTarget state:\n";
102 std::cout << boost::format(
"found %g moves\n") % moves.size();
104 for (WMoveContainer::const_iterator each = moves.begin();
105 each != moves.end(); ++each)
107 std::cout << boost::format(
"[%g] %g") % each->getWeight() % each->getMove();
108 const int next_index = each->getStateIndex();
115 void doMain(
const std::string& file_name)
118 boost::shared_ptr<osl::record::Characters>(
121 if (
vm.count(
"verbose"))
122 std::cout << boost::format(
"Opening... %s\n ") % file_name;
125 if (
vm.count(
"verbose"))
131 int state_index_to_compare = -1;
135 typedef std::pair<int, int> state_depth_t;
138 if (
vm.count(
"verbose"))
144 typedef std::pair<int, int> eval_depth_t;
145 std::deque<eval_depth_t> evals;
146 long finishing_games = 0;
148 while (!stateToVisit.empty())
150 const state_depth_t state_depth = stateToVisit.back();
151 if (
vm.count(
"verbose"))
152 std::cout << boost::format(
"Visiting... %d\n") % state_depth.first;
153 const int stateIndex = state_depth.first;
154 const int depth = state_depth.second;
155 stateToVisit.pop_back();
156 states[stateIndex] =
true;
162 state_index_to_compare == stateIndex)
166 if (
vm.count(
"verbose"))
167 std::cout << boost::format(
" #moves... %d\n") % moves.size();
171 if ( !moves.empty() &&
179 min = moves.at(0).getWeight();
184 const int weight = moves.at(i).getWeight();
185 if ((
double)weight < (
double)moves.at(i-1).getWeight()*
ratio)
192 if (min == 0) min = 1;
194 WMoveContainer::iterator each = moves.begin();
195 for (; each != moves.end(); ++each)
197 if (each->getWeight() <
min)
200 moves.erase(each, moves.end());
214 std::cerr << std::endl;
215 std::cerr <<
"eval: " << value << std::endl;
216 printer.
print(state);
217 std::cerr <<
"piece value:" << osl::PieceEval(state).value() <<
"\n" << state;
222 evals.push_back(eval_depth_t(value, depth));
231 for (std::vector<osl::record::opening::WMove>::const_iterator each = moves.begin();
232 each != moves.end(); ++each)
235 const osl::SimpleState state(
book.
getBoard(stateIndex));
237 const int nextIndex = each->getStateIndex();
238 const osl::SimpleState next_state(
book.
getBoard(nextIndex));
241 if (moved_hash != next_hash)
242 throw std::string(
"Illegal move found.");
244 if (! states[nextIndex])
245 stateToVisit.push_back(state_depth_t(nextIndex, depth+1));
250 std::cout << std::endl;
251 std::cout << boost::format(
"Book: %s\n") % file_name;
252 std::cout << boost::format(
"Player: %s\n") %
the_player;
253 std::cout <<
"FU=128 points\n";
255 boost::format(
"#states: %d (+ %d finishing games over %d points; max %d)\n")
261 std::cout <<
"Eval\n";
263 for (std::deque<eval_depth_t>::const_iterator each = evals.begin();
264 each != evals.end(); ++each)
265 tmp.push_back(each->first);
269 std::cout <<
"Depth\n";
271 for (std::deque<eval_depth_t>::const_iterator each = evals.begin();
272 each != evals.end(); ++each)
273 tmp.push_back(each->second);
278 std::cout <<
"\nthe state hits: " <<
state_count << std::endl;
285 std::cout <<
"\nNo parent\n";
290 for (std::vector<int>::const_iterator each = parents.begin();
291 each != parents.end(); ++each, ++i)
293 std::cout << boost::format(
"\n--- Parent: %g ---\n ") % i;
302 int main(
int argc,
char **argv)
304 std::string player_str;
305 std::string file_name;
306 size_t csa_move_index;
307 std::string csa_file_name;
309 bp::options_description command_line_options;
310 command_line_options.add_options()
311 (
"player,p", bp::value<std::string>(&player_str)->default_value(
"black"),
312 "specify a player, black or white, in whose point of view the book is validated. "
314 (
"input-file,f", bp::value<std::string>(&file_name)->default_value(
"./joseki.dat"),
315 "a joseki file to validate.")
316 (
"dump", bp::value<bool>(&
is_dump)->default_value(
false),
317 "dump finishing games' states")
319 "threshold of evaluatoin value to recognize a finishing game.")
320 (
"determinate", bp::value<int>(&
is_determinate)->default_value(0),
321 "only search the top n moves. (0 for all, 1 for determinate).")
323 "use the best move where the depth is greater than this value")
324 (
"max-depth", bp::value<int>(&
max_depth)->default_value(100),
325 "do not go beyond this depth from the root")
326 (
"ratio", bp::value<double>(&
ratio)->default_value(0.0),
327 "skip move[i] (i >= n), if weight[n] < weight[n-1]*ratio")
328 (
"csa-move", bp::value<size_t>(&csa_move_index)->default_value(1),
329 "n-th-move state in the csa file")
330 (
"csa", bp::value<std::string>(&csa_file_name)->default_value(
""),
331 "a csa file name. See if a state in the game exists in the book or not.")
332 (
"quick", bp::value<bool>(&
is_quick)->default_value(
false),
333 "skip quiescence search.")
334 (
"verbose,v",
"output verbose messages.")
335 (
"help,h",
"show this help message.");
336 bp::positional_options_description p;
337 p.add(
"input-file", 1);
342 bp::command_line_parser(
343 argc, argv).options(command_line_options).positional(p).
run(),
vm);
345 if (
vm.count(
"help"))
347 printUsage(std::cout, argv, command_line_options);
351 catch (std::exception &e)
353 std::cerr <<
"error in parsing options\n"
354 << e.what() << std::endl;
355 printUsage(std::cerr, argv, command_line_options);
359 if (player_str ==
"black")
361 else if (player_str ==
"white")
365 printUsage(std::cerr, argv, command_line_options);
369 if (!csa_file_name.empty())
378 if (csa_move_index < 1) csa_move_index = 1;
379 if (csa_move_index > moves.size()) csa_move_index = moves.size();
383 std::cout <<
"Invalid csa move index: " << csa_move_index << std::endl;
386 for (
size_t i=0; i < csa_move_index; i++)