Go to the documentation of this file.00001 #include "osl/record/opening/openingBook.h"
00002 #include "osl/state/simpleState.h"
00003 #include "osl/record/csa.h"
00004 #include "osl/record/csaRecord.h"
00005 #include "osl/stl/hash_map.h"
00006 #include "osl/hash/hashKey.h"
00007 #include "osl/oslConfig.h"
00008 #include <boost/foreach.hpp>
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 typedef hash_map<HashKey, WeightedBook::WMoveContainer> state_map;
00017 void show(const std::string& filename,
00018 const state_map& states, const SimpleState& state)
00019 {
00020 state_map::const_iterator it = states.find(HashKey(state));
00021 if (it == states.end())
00022 {
00023 std::cout << filename << "\t" << "Not found" << std::endl;
00024 }
00025 else
00026 {
00027 std::cout << filename;
00028 const WeightedBook::WMoveContainer &moves = it->second;
00029 for (size_t j = 0; j < moves.size(); ++j)
00030 {
00031 std::cout << "\t" << osl::record::csa::show(moves[j].getMove())
00032 << "\t" << moves[j].getWeight();
00033 }
00034 std::cout << std::endl;
00035 }
00036 }
00037 int main(int argc, char **argv)
00038 {
00039 std::string book_filename = OslConfig::openingBook();
00040 WeightedBook book(book_filename.c_str());
00041
00042 state_map states;
00043 {
00044 std::vector<int> state_stack;
00045 state_stack.push_back(book.getStartState());
00046
00047 while (!state_stack.empty())
00048 {
00049 const int index = state_stack.back();
00050 state_stack.pop_back();
00051
00052 const SimpleState state = book.getBoard(index);
00053 const HashKey key = HashKey(state);
00054 if (states.find(key) == states.end())
00055 {
00056 WeightedBook::WMoveContainer moves = book.getMoves(index);
00057 for (size_t i = 0; i < moves.size(); ++i)
00058 {
00059 state_stack.push_back(moves[i].getStateIndex());
00060 }
00061 states[key] = moves;
00062 }
00063 }
00064 }
00065
00066 for (int i = 1; i < argc; ++i)
00067 {
00068 const std::string filename(argv[i]);
00069 osl::record::csa::CsaFile csa(filename);
00070
00071 NumEffectState state = csa.getInitialState();
00072 vector<Move> record_moves = csa.getRecord().getMoves();
00073 if (record_moves.empty() || !(state == SimpleState(HIRATE)))
00074 show(filename, states, state);
00075 BOOST_FOREACH(Move move, record_moves) {
00076 state.makeMove(move);
00077 show(filename, states, state);
00078 }
00079 }
00080
00081 return 0;
00082 }
00083
00084
00085
00086