12 for (
int i=0;i<4;i++) {
13 ret = (ret<<8)|(cs[i]&255);
21 for (
int i = 0; i < 4; i++)
23 buf[i] = (n >> (8 * (4 - i - 1))) & 255;
31 : ifs(filename,
std::ios_base::binary)
35 const char *message =
"WinCountBook: open failed ";
36 std::cerr << message << filename << std::endl;
37 throw std::runtime_error(std::string(message) + filename);
53 for (
int i=0;i<4;i++) {
54 ret = (ret<<8)|(cs[i]&255);
62 ifs.seekg(offset,std::ios::beg);
68 assert(stateIndex >= 0);
69 seek(4+16*stateIndex+8);
72 seek(4+16*nStates+8*moveIndex);
73 std::vector<OBMove> moves;
74 moves.reserve(nMoves);
75 for(
int i=0;i<nMoves;i++)
79 moves.push_back({move,stateIndex});
87 seek(4+16*stateIndex);
94 seek(4+16*stateIndex+4);
117 : ifs(filename,
std::ios_base::binary)
121 const char *message =
"WeightedBook: open failed ";
122 std::cerr << message << filename << std::endl;
123 throw std::runtime_error(std::string(message) + filename);
129 assert(version == 1);
143 ifs.seekg(offset,std::ios::beg);
149 assert(stateIndex >= 0);
150 seek(HEADER_SIZE + STATE_SIZE * stateIndex);
153 seek(HEADER_SIZE + STATE_SIZE * n_states + MOVE_SIZE * moveIndex);
154 std::vector<WMove> moves;
155 moves.reserve(nWMoves);
156 for(
int i=0;i<nWMoves;i++)
160 if (!visit_zero && wm.
weight == 0)
continue;
169 seek(HEADER_SIZE + STATE_SIZE * n_states + MOVE_SIZE * n_moves
170 + BOARD_SIZE * stateIndex);
180 return board.
state();
186 seek(HEADER_SIZE + STATE_SIZE * stateIndex);
196 seek(HEADER_SIZE + STATE_SIZE * stateIndex);
209 assert(state == start);
212 std::vector<char> visited(n_states);
213 std::fill(visited.begin(), visited.end(),
false);
215 std::vector<int> stateToCheck;
216 stateToCheck.push_back(start_state);
217 visited[start_state] =
true;
219 while (!stateToCheck.empty())
221 const int index = stateToCheck.back();
222 stateToCheck.pop_back();
224 for (
WMove move: moves(index))
228 const int nextIndex = move.stateIndex();
231 assert(newState == stateInFile);
232 if (!visited[nextIndex])
234 stateToCheck.push_back(nextIndex);
235 visited[nextIndex] =
true;
243 const bool visit_zero,
247 const CompactBoard board_to_look_for(state_to_look_for);
249 const CompactBoard start_state = compactBoard(startState());
250 if (start_state == board_to_look_for)
256 std::vector<char> states(totalState(),
false);
257 std::vector<int> stateToVisit;
258 stateToVisit.push_back(startState());
260 while (!stateToVisit.empty())
262 const int stateIndex = stateToVisit.back();
263 stateToVisit.pop_back();
264 states[stateIndex] =
true;
268 v = moves(stateIndex);
271 const CompactBoard stateIndexCB = compactBoard(stateIndex);
273 const bool zero_include = turn == player ? false :
true;
274 v = moves(stateIndex, zero_include);
278 const int nextIndex = move.stateIndex();
279 if (! states[nextIndex])
282 if (state == board_to_look_for)
288 stateToVisit.push_back(nextIndex);
299 int state_index = startState();
300 for (
Move move: moves)
302 const WMoveContainer wmoves = this->moves(state_index);
303 WMoveContainer::const_iterator it = wmoves.begin();
304 for (; it != wmoves.end(); ++it)
305 if (it->move == move)
break;
306 if (it != wmoves.end())
308 state_index = it->stateIndex();
320 std::vector<int> ret;
322 if (startState() == target_state_index)
325 std::vector<char> states(totalState(),
false);
326 std::vector<int> stateToVisit;
327 stateToVisit.push_back(startState());
329 while (!stateToVisit.empty())
331 const int stateIndex = stateToVisit.back();
332 stateToVisit.pop_back();
333 states[stateIndex] =
true;
336 for (
WMove move: moves)
338 const int nextIndex = move.stateIndex();
340 if (nextIndex == target_state_index)
341 ret.push_back(stateIndex);
343 if (! states[nextIndex])
344 stateToVisit.push_back(nextIndex);
static const Move makeDirect(int value)
SimpleStateよりcompactな局面の表現
SimpleState state() const
int blackWinCount(int stateIndex)
SimpleState board(int stateIndex)
WMoveContainer moves(int stateIndex, const bool zero_include=true)
Return moves from the state of the stateIndex.
std::vector< WMove > WMoveContainer
CompactBoard compactBoard(int stateIndex)
int stateIndex(const SimpleState &state, const bool visit_zero=true, const Player player=BLACK)
As traversing the 'tree', find a state index of the state.
int whiteWinCount(int stateIndex)
std::vector< int > parents(const int stateIndex)
As traversing the 'tree', return all state indices of the state's parents.
WeightedBook(const char *filename)
int winCount(int stateIndex)
std::vector< OBMove > moves(int stateIndex)
int loseCount(int stateIndex)
WinCountBook(const char *filename)
std::ostream & operator<<(std::ostream &os, const CompactBoard &c)
std::istream & operator>>(std::istream &os, CompactBoard &c)
void writeInt(std::ostream &os, int n)
int readInt(std::istream &is)