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);
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);
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;
180 return board.
state();
209 assert(state == start);
212 std::vector<char> visited(
n_states);
213 std::fill(visited.begin(), visited.end(),
false);
215 std::vector<int> stateToCheck;
219 while (!stateToCheck.empty())
221 const int index = stateToCheck.back();
222 stateToCheck.pop_back();
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);
250 if (start_state == board_to_look_for)
256 std::vector<char> states(
totalState(),
false);
257 std::vector<int> stateToVisit;
260 while (!stateToVisit.empty())
263 stateToVisit.pop_back();
268 v =
moves(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);
300 for (
Move move: moves)
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;
325 std::vector<char> states(
totalState(),
false);
326 std::vector<int> stateToVisit;
329 while (!stateToVisit.empty())
332 stateToVisit.pop_back();
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);
std::ostream & operator<<(std::ostream &os, const CompactBoard &c)
WMoveContainer moves(int stateIndex, const bool zero_include=true)
Return moves from the state of the stateIndex.
int loseCount(int stateIndex)
static const Move makeDirect(int value)
std::vector< OBMove > moves(int stateIndex)
static const int HEADER_SIZE
SimpleState board(int stateIndex)
SimpleState state() const
std::istream & operator>>(std::istream &os, CompactBoard &c)
std::vector< WMove > WMoveContainer
int whiteWinCount(int stateIndex)
int readInt(std::istream &is)
WinCountBook(const char *filename)
SimpleStateよりcompactな局面の表現
static const int STATE_SIZE
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.
static const int MOVE_SIZE
WeightedBook(const char *filename)
int blackWinCount(int stateIndex)
std::vector< int > parents(const int stateIndex)
As traversing the 'tree', return all state indices of the state's parents.
void writeInt(std::ostream &os, int n)
static const int BOARD_SIZE
CompactBoard compactBoard(int stateIndex)
int winCount(int stateIndex)