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