osl::book::WeightedBook Class Reference

StateとWMoveを保持する. More...

`#include <openingBook.h>`

## Public Types

typedef std::vector< WMove > | WMoveContainer

## Public Member Functions

| WeightedBook (const char *filename)
| ~WeightedBook ()
WMoveContainer | moves (int stateIndex, const bool zero_include=true)
| Return moves from the state of the stateIndex.
int | whiteWinCount (int stateIndex)
int | blackWinCount (int stateIndex)
CompactBoard | compactBoard (int stateIndex)
SimpleState | board (int stateIndex)
int | totalState () const
int | startState () const
void | validate ()
std::vector< int > | parents (const int stateIndex)
| As traversing the 'tree', return all state indices of the state's parents.
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 | stateIndex (const std::vector< Move > &moves)
| As traversing the 'tree', find a state index of the state reached by applying the moves from the initial state.

## Private Member Functions

void | seek (int offset)

## Private Attributes

int | n_states
int | n_moves
int | start_state
std::ifstream | ifs

## Static Private Attributes

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

## Detailed Description

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数

Definition at line 168 of file openingBook.h.

## Member Typedef Documentation

## WMoveContainer

typedef std::vector<WMove> osl::book::WeightedBook::WMoveContainer

Definition at line 175 of file openingBook.h.

## Constructor & Destructor Documentation

## WeightedBook()

osl::book::WeightedBook::WeightedBook | ( | const char * | filename | ) |

Definition at line 115 of file openingBook.cc.

References ifs, n_moves, n_states, osl::book::readInt(), and start_state.

## ~WeightedBook()

osl::book::WeightedBook::~WeightedBook | ( |  | ) |

Definition at line 135 of file openingBook.cc.

## Member Function Documentation

## blackWinCount()

int osl::book::WeightedBook::blackWinCount | ( | int | stateIndex | ) |

Definition at line 193 of file openingBook.cc.

References HEADER_SIZE, ifs, osl::book::readInt(), seek(), STATE_SIZE, and stateIndex().

## board()

osl::SimpleState osl::book::WeightedBook::board | ( | int | stateIndex | ) |

Definition at line 176 of file openingBook.cc.

References board(), compactBoard(), and stateIndex().

Referenced by board(), compactBoard(), and validate().

## compactBoard()

osl::book::CompactBoard osl::book::WeightedBook::compactBoard | ( | int | stateIndex | ) |

Definition at line 166 of file openingBook.cc.

References board(), BOARD_SIZE, HEADER_SIZE, ifs, MOVE_SIZE, n_moves, n_states, seek(), STATE_SIZE, and stateIndex().

Referenced by board(), and stateIndex().

## moves()

osl::book::WeightedBook::WMoveContainer osl::book::WeightedBook::moves | ( | int | stateIndex,
|  | const bool | zero_include = true )

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.

Definition at line 146 of file openingBook.cc.

References HEADER_SIZE, ifs, MOVE_SIZE, moves(), n_states, osl::book::readInt(), seek(), STATE_SIZE, stateIndex(), and osl::book::WMove::weight.

Referenced by moves(), parents(), stateIndex(), stateIndex(), and validate().

## parents()

std::vector< int > osl::book::WeightedBook::parents | ( | const int | stateIndex | ) |

As traversing the 'tree', return all state indices of the state's parents.

Returns
  state indexes; empty if there is none.

Definition at line 317 of file openingBook.cc.

References moves(), startState(), stateIndex(), and totalState().

## seek()

void osl::book::WeightedBook::seek | ( | int | offset | ) |

private

Definition at line 140 of file openingBook.cc.

References ifs.

Referenced by blackWinCount(), compactBoard(), moves(), and whiteWinCount().

## startState()

int osl::book::WeightedBook::startState | ( |  | ) | const

inline

Definition at line 190 of file openingBook.h.

References start_state.

Referenced by parents(), and stateIndex().

## stateIndex() [1/2]

int osl::book::WeightedBook::stateIndex | ( | const SimpleState & | state,
|  | const bool | visit_zero = true,
|  | const Player | player = BLACK )

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.

Parameters

  state | to find
  visit_zero |
  player |

Returns
  a state index of the state; if it is not found, return -1.

Definition at line 241 of file openingBook.cc.

References compactBoard(), moves(), start_state, startState(), stateIndex(), totalState(), and osl::book::CompactBoard::turn().

Referenced by blackWinCount(), board(), compactBoard(), moves(), parents(), stateIndex(), and whiteWinCount().

## stateIndex() [2/2]

int osl::book::WeightedBook::stateIndex | ( | const std::vector< Move > & | moves | ) |

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.

Parameters

  moves | to apply

Returns
  state index; if it is not found, return -1.

References moves().

## totalState()

int osl::book::WeightedBook::totalState | ( |  | ) | const

inline

Definition at line 189 of file openingBook.h.

References n_states.

Referenced by parents(), and stateIndex().

## validate()

void osl::book::WeightedBook::validate | ( |  | ) |

Definition at line 202 of file openingBook.cc.

References board(), osl::HIRATE, osl::NumEffectState::makeMove(), moves(), n_states, and start_state.

## whiteWinCount()

int osl::book::WeightedBook::whiteWinCount | ( | int | stateIndex | ) |

Definition at line 183 of file openingBook.cc.

References HEADER_SIZE, ifs, osl::book::readInt(), seek(), STATE_SIZE, and stateIndex().

## Member Data Documentation

## BOARD_SIZE

const int osl::book::WeightedBook::BOARD_SIZE = 41 * 4

static private

Definition at line 226 of file openingBook.h.

Referenced by compactBoard().

## HEADER_SIZE

const int osl::book::WeightedBook::HEADER_SIZE = 16

static private

Definition at line 223 of file openingBook.h.

Referenced by blackWinCount(), compactBoard(), moves(), and whiteWinCount().

## ifs

std::ifstream osl::book::WeightedBook::ifs

private

Definition at line 173 of file openingBook.h.

Referenced by blackWinCount(), compactBoard(), moves(), seek(), WeightedBook(), and whiteWinCount().

## MOVE_SIZE

const int osl::book::WeightedBook::MOVE_SIZE = 12

static private

Definition at line 225 of file openingBook.h.

Referenced by compactBoard(), and moves().

## n_moves

int osl::book::WeightedBook::n_moves

private

Definition at line 171 of file openingBook.h.

Referenced by compactBoard(), and WeightedBook().

## n_states

int osl::book::WeightedBook::n_states

private

Definition at line 170 of file openingBook.h.

Referenced by compactBoard(), moves(), totalState(), validate(), and WeightedBook().

## start_state

int osl::book::WeightedBook::start_state

private

Definition at line 172 of file openingBook.h.

Referenced by startState(), stateIndex(), validate(), and WeightedBook().

## STATE_SIZE

const int osl::book::WeightedBook::STATE_SIZE = 16

static private

Definition at line 224 of file openingBook.h.

Referenced by blackWinCount(), compactBoard(), moves(), and whiteWinCount().

The documentation for this class was generated from the following files:

- openingBook.h
- openingBook.cc