show-moves.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
show-moves.cc
Go to the documentation of this file.
1 #include "osl/record/opening/openingBook.h"
2 #include "osl/state/simpleState.h"
3 #include "osl/record/csa.h"
4 #include "osl/record/csaRecord.h"
5 #include "osl/stl/hash_map.h"
6 #include "osl/hash/hashKey.h"
7 #include "osl/oslConfig.h"
8 #include <boost/foreach.hpp>
9 #include <iostream>
10
11 using namespace osl;
12 using namespace osl::record;
13 using namespace osl::record::opening;
14 using namespace osl::stl;
15
16 typedef hash_map<HashKey, WeightedBook::WMoveContainer> state_map;
17 void show(const std::string& filename,
18 const state_map& states, const SimpleState& state)
19 {
20 state_map::const_iterator it = states.find(HashKey(state));
21 if (it == states.end())
22 {
23 std::cout << filename << "\t" << "Not found" << std::endl;
24 }
25 else
26 {
27 std::cout << filename;
28 const WeightedBook::WMoveContainer &moves = it->second;
29 for (size_t j = 0; j < moves.size(); ++j)
30 {
31 std::cout << "\t" << osl::record::csa::show(moves[j].getMove())
32 << "\t" << moves[j].getWeight();
33 }
34 std::cout << std::endl;
35 }
36 }
37 int main(int argc, char **argv)
38 {
39 std::string book_filename = OslConfig::openingBook();
40 WeightedBook book(book_filename.c_str());
41
42 state_map states;
43 {
44 std::vector<int> state_stack;
45 state_stack.push_back(book.getStartState());
46
47 while (!state_stack.empty())
48 {
49 const int index = state_stack.back();
50 state_stack.pop_back();
51
52 const SimpleState state = book.getBoard(index);
53 const HashKey key = HashKey(state);
54 if (states.find(key) == states.end())
55 {
56 WeightedBook::WMoveContainer moves = book.getMoves(index);
57 for (size_t i = 0; i < moves.size(); ++i)
58 {
59 state_stack.push_back(moves[i].getStateIndex());
60 }
61 states[key] = moves;
62 }
63 }
64 }
65
66 for (int i = 1; i < argc; ++i)
67 {
68 const std::string filename(argv[i]);
69 osl::record::csa::CsaFile csa(filename);
70
71 NumEffectState state = csa.getInitialState();
72 vector<Move> record_moves = csa.getRecord().getMoves();
73 if (record_moves.empty() || !(state == SimpleState(HIRATE)))
74 show(filename, states, state);
75 BOOST_FOREACH(Move move, record_moves) {
76 state.makeMove(move);
77 show(filename, states, state);
78 }
79 }
80
81 return 0;
82 }
83 // ;;; Local Variables:
84 // ;;; mode:c++
85 // ;;; c-basic-offset:2
86 // ;;; End: