/usr/include/osl/book/openingBook.h is in libosl-dev 0.8.0-1.4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | #ifndef _OPENING_BOOK_H
#define _OPENING_BOOK_H
#include "osl/book/compactBoard.h"
#include "osl/basic_type.h"
#include "osl/numEffectState.h"
#include <fstream>
#include <functional>
namespace osl
{
namespace book
{
class OMove
{
public:
OMove(int i) { value = i; }
OMove(Move m) {
const Square from = m.from();
const Square to = m.to();
const int bitFrom = (from.isPieceStand() ? 0 :
(from.x() << 4 | from.y()));
const int bitTo = (to.isPieceStand() ? 0 :
(to.x() << 12 | to.y() << 8));
value = (bitFrom | bitTo |
static_cast<unsigned int>(m.isPromotion()) << 19 |
static_cast<unsigned int>(m.capturePtype()) << 20 |
static_cast<unsigned int>(m.ptype()) << 24 |
static_cast<int>(m.player()) << 28);
}
Square from() {
if ((value & 0xff) == 0)
return Square::STAND();
else
return Square((value >> 4) & 0xf, value & 0xf);
}
Square to() {
if (((value >> 8) & 0xff) == 0)
return Square::STAND();
else
return Square((value >> 12) & 0xf, (value >> 8) & 0xf);
}
bool isPromotion() { return (value >> 19) & 1; }
Ptype capturePtype() {
return static_cast<Ptype>((value >> 20) & 0xf);
}
Ptype ptype() {
return static_cast<Ptype>((value >> 24) & 0xf);
}
Player player() {
return static_cast<Player>((value) >> 28);
}
operator Move() { return Move(from(), to(), ptype(),
capturePtype(), isPromotion(),
player()); }
operator int() { return value; }
private:
int value;
};
struct OBMove
{
Move move;
int state_index;
int stateIndex() const { return state_index; }
};
/**
* StateとOBMoveを保持する.
* Stateはvector<OBMove>と黒から見たwinCount, loseCountを保持する
* OBMoveはMoveとそのMoveを採用した時のStateのindex
* ファイル形式
* state数 - 4byte
* State - 16byte * state数
* + 黒のwinCount
* + 白のwinCount
* + OBMoveの数
* + OBMoveの開始index
* OBMove - 8byte * OBMove数
* + Move (4byte)
* + Stateのindex
*/
class WinCountBook
{
int nStates;
std::ifstream ifs;
public:
WinCountBook(const char *filename);
~WinCountBook();
int winCount(int stateIndex);
int loseCount(int stateIndex);
std::vector<OBMove> moves(int stateIndex);
private:
int readInt();
void seek(int offset);
};
struct WMove
{
Move move;
int state_index;
int weight;
int stateIndex() const { return state_index; }
void setWeight(const int w) { weight = w; };
};
std::ostream& operator<<(std::ostream&, const WMove& w);
std::istream& operator>>(std::istream&, WMove& w);
inline bool operator==(const WMove& l, const WMove& r)
{
return l.move == r.move && l.stateIndex() == r.stateIndex()
&& l.weight == r.weight;
}
/**
* WMoveのWeightによるsort
*/
struct WMoveSort : public std::binary_function<WMove, WMove, bool>
{
bool operator()(const WMove& l, const WMove& r) const {
return l.weight > r.weight;
}
};
/**
* WMoveのMoveによるsort
*/
struct WMoveMoveSort : public std::binary_function<WMove, WMove, bool>
{
bool operator()(const WMove& l, const WMove& r) const {
return l.move.intValue() < r.move.intValue();
}
};
/**
* WMoveのWeightとMoveによるsort
*/
struct WMoveWeightMoveSort : public std::binary_function<WMove, WMove, bool>
{
bool operator()(const WMove& l, const WMove& r) const {
if (l.weight != r.weight)
return l.weight > r.weight;
return l.move.intValue() < r.move.intValue();
}
};
/**
* StateとWMoveを保持する.
* Stateはvector<WMove>を保持する
* WMoveはMoveとそのMoveを採用した時のStateのindexと手番から見た
* Moveの重み(0-1000)をもつ
* ファイル形式
* version番号 - 4byte
* state数 - 4byte
* move数 - 4byte
* 開始state index - 4byte
* State - 16byte * state数
* + WMoveの開始index
* + WMoveの数
* + 先手の勝数
* + 後手の勝数
* WMove - 12byte * WMove数
* + Move (4byte)
* + Stateのindex
* + Weight
* CompactBoard形式の盤面 - 164byte * state数
*/
class WeightedBook
{
int n_states;
int n_moves;
int start_state;
std::ifstream ifs;
public:
typedef std::vector<WMove> WMoveContainer;
WeightedBook(const char *filename);
~WeightedBook();
/**
* Return moves from the state of the stateIndex. If the zero_include is
* true, all of the moves are returned. Otherwise, the moves that
* have some weights (i.e. non-zero value) are returned.
*/
WMoveContainer moves(int stateIndex, const bool zero_include = true);
int whiteWinCount(int stateIndex);
int blackWinCount(int stateIndex);
CompactBoard compactBoard(int stateIndex);
SimpleState board(int stateIndex);
int totalState() const { return n_states; }
int startState() const { return start_state; }
void validate();
/**
* As traversing the 'tree', return all state indices of the state's
* parents.
* @return state indexes; empty if there is none.
*/
std::vector<int> parents(const int stateIndex);
/**
* As traversing the 'tree', find a state index of the state. If
* the visit_zero is true zero-weighted moves are visited (in this
* case, player is ignored). Otherwise, the palyer's zero-weighted
* moves are not visited.
*
* @param state to find
* @param visit_zero
* @param player
* @return a state index of the state; if it is not found, return -1.
*/
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 reached
* by applying the moves from the initial state.
* Note that zero-weighted moves are visited.
*
* @param moves to apply
* @return state index; if it is not found, return -1.
*/
int stateIndex(const std::vector<Move>& moves);
private:
void seek(int offset);
static const int HEADER_SIZE = 16;
static const int STATE_SIZE = 16;
static const int MOVE_SIZE = 12;
static const int BOARD_SIZE = 41 * 4;
};
} // book
using book::CompactBoard;
using book::WeightedBook;
} // namespace osl
#endif // _OPENING_BOOK_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|