00001 #include "osl/record/opening/openingBook.h" 00002 #include "osl/state/simpleState.h" 00003 #include "osl/apply_move/applyMove.h" 00004 #include "osl/record/csa.h" 00005 #include "osl/record/csaRecord.h" 00006 #include "osl/stl/hash_map.h" 00007 #include "osl/hash/hashKey.h" 00008 00009 #include <iostream> 00010 00011 using namespace osl; 00012 using namespace osl::record; 00013 using namespace osl::record::opening; 00014 using namespace osl::stl; 00015 00016 struct HashSimpleState 00017 { 00018 unsigned long operator() (const osl::state::SimpleState &state) const 00019 { 00020 return osl::hash::HashKey(state).signature(); 00021 } 00022 }; 00023 00024 int main(int argc, char **argv) 00025 { 00026 std::string book_filename = "../data/joseki.dat"; 00027 WeightedBook book(book_filename.c_str()); 00028 00029 typedef hash_map<SimpleState, WeightedBook::WMoveContainer, 00030 HashSimpleState> state_map; 00031 00032 state_map states; 00033 { 00034 std::vector<int> state_stack; 00035 state_stack.push_back(book.getStartState()); 00036 00037 while (!state_stack.empty()) 00038 { 00039 const int index = state_stack.back(); 00040 state_stack.pop_back(); 00041 00042 const SimpleState state = book.getBoard(index); 00043 if (states.find(state) == states.end()) 00044 { 00045 WeightedBook::WMoveContainer moves = book.getMoves(index); 00046 for (size_t i = 0; i < moves.size(); ++i) 00047 { 00048 state_stack.push_back(moves[i].getStateIndex()); 00049 } 00050 states[state] = moves; 00051 } 00052 } 00053 } 00054 00055 for (int i = 1; i < argc; ++i) 00056 { 00057 const std::string filename(argv[i]); 00058 osl::record::csa::CsaFile csa(filename); 00059 00060 const SimpleState state = csa.getInitialState(); 00061 state_map::const_iterator it = states.find(state); 00062 if (it == states.end()) 00063 { 00064 std::cout << filename << "\t" << "Not found" << std::endl; 00065 } 00066 else 00067 { 00068 std::cout << filename; 00069 const WeightedBook::WMoveContainer &moves = it->second; 00070 for (size_t j = 0; j < moves.size(); ++j) 00071 { 00072 std::cout << "\t" << osl::record::csa::show(moves[j].getMove()) 00073 << "\t" << moves[j].getWeight(); 00074 } 00075 std::cout << std::endl; 00076 } 00077 } 00078 00079 return 0; 00080 }