4 #include <boost/random/mersenne_twister.hpp> 
    5 #include <boost/random/uniform_int.hpp> 
    6 #include <boost/foreach.hpp> 
   14   : ifs(filename, std::ios_base::binary)
 
   18     const char *message = 
"WinCountBook: open failed ";
 
   19     std::cerr << message << filename << std::endl;
 
   20     throw std::runtime_error(std::string(message) + filename);
 
   36   for (
int i=0;i<4;i++) {
 
   37     ret = (ret<<8)|(cs[i]&255);
 
   45   ifs.seekg(offset,std::ios::beg);
 
   51   assert(stateIndex >= 0);
 
   52   seek(4+16*stateIndex+8);
 
   55   seek(4+16*nStates+8*moveIndex);
 
   57   moves.reserve(nMoves);
 
   58   for(
int i=0;i<nMoves;i++)
 
   62     moves.push_back(
OBMove(move,stateIndex));
 
   70   seek(4+16*stateIndex);
 
   77   seek(4+16*stateIndex+4);
 
  100   : ifs(filename, std::ios_base::binary)
 
  104     const char *message = 
"WeightedBook: open failed ";
 
  105     std::cerr << message << filename << std::endl;
 
  106     throw std::runtime_error(std::string(message) + filename);
 
  112   assert(version == 1);
 
  126   ifs.seekg(offset,std::ios::beg);
 
  132   assert(stateIndex >= 0);
 
  133   seek(HEADER_SIZE + STATE_SIZE * stateIndex);
 
  136   seek(HEADER_SIZE + STATE_SIZE * nStates + MOVE_SIZE * moveIndex);
 
  138   moves.reserve(nWMoves);
 
  139   for(
int i=0;i<nWMoves;i++)
 
  143     if (!visit_zero && wm.getWeight() == 0) 
continue;
 
  152   seek(HEADER_SIZE + STATE_SIZE * nStates + MOVE_SIZE * nMoves
 
  153        + BOARD_SIZE * stateIndex);
 
  169   seek(HEADER_SIZE + STATE_SIZE * stateIndex);
 
  179   seek(HEADER_SIZE + STATE_SIZE * stateIndex);
 
  190     SimpleState state(
HIRATE);
 
  191     SimpleState start = getBoard(startState);
 
  192     assert(state == start);
 
  195   vector<char> visited(nStates);
 
  196   std::fill(visited.begin(), visited.end(), 
false);
 
  198   vector<int> stateToCheck;
 
  199   stateToCheck.push_back(startState);
 
  200   visited[startState] = 
true;
 
  202   while (!stateToCheck.empty())
 
  204     const int index = stateToCheck.back();
 
  205     stateToCheck.pop_back();
 
  206     SimpleState state = getBoard(index);
 
  207     vector<record::opening::WMove> 
moves = getMoves(index);
 
  208     BOOST_FOREACH(
WMove move, moves)
 
  210       NumEffectState newState(state);
 
  211       newState.makeMove(move.
getMove());
 
  214       SimpleState stateInFile = getBoard(nextIndex);
 
  215       assert(newState == stateInFile);
 
  216       if (!visited[nextIndex])
 
  218         stateToCheck.push_back(nextIndex);
 
  219         visited[nextIndex] = 
true;
 
  227                             const bool visit_zero, 
 
  231   const CompactBoard board_to_look_for(state_to_look_for);
 
  233   const CompactBoard start_state = getCompactBoard(getStartState());
 
  234   if (start_state == board_to_look_for)
 
  236     ret = getStartState();
 
  240   vector<char> states(getTotalState(), 
false); 
 
  241   vector<int> stateToVisit;
 
  242   stateToVisit.push_back(getStartState());
 
  244   while (!stateToVisit.empty())
 
  246     const int stateIndex = stateToVisit.back();
 
  247     stateToVisit.pop_back();
 
  248     states[stateIndex] = 
true;
 
  252       moves = getMoves(stateIndex);
 
  255       const CompactBoard stateIndexCB = getCompactBoard(stateIndex);
 
  257       const bool zero_include = turn == player ? 
false : 
true;
 
  258       moves = getMoves(stateIndex, zero_include);
 
  260     BOOST_FOREACH(
WMove move, moves)
 
  263       if (! states[nextIndex])
 
  266         if (state == board_to_look_for)
 
  272         stateToVisit.push_back(nextIndex);
 
  283   int state_index = getStartState();
 
  284   BOOST_FOREACH(
Move move, moves)
 
  287     WMoveContainer::const_iterator it = wmoves.begin();
 
  288     for (; it != wmoves.end(); ++it)
 
  289       if (it->getMove() == move) 
break;
 
  290     if (it != wmoves.end())
 
  292       state_index = it->getStateIndex(); 
 
  304   std::vector<int> ret;
 
  306   if (getStartState() == target_state_index)
 
  309   vector<char> states(getTotalState(), 
false); 
 
  310   vector<int> stateToVisit;
 
  311   stateToVisit.push_back(getStartState());
 
  313   while (!stateToVisit.empty())
 
  315     const int stateIndex = stateToVisit.back();
 
  316     stateToVisit.pop_back();
 
  317     states[stateIndex] = 
true;
 
  320     BOOST_FOREACH(
WMove move, moves)
 
  324       if (nextIndex == target_state_index)
 
  325         ret.push_back(stateIndex);
 
  327       if (! states[nextIndex])
 
  328         stateToVisit.push_back(nextIndex);