diff --git a/Rapfi/command/database.cpp b/Rapfi/command/database.cpp index 04e608c..3ad70fd 100644 --- a/Rapfi/command/database.cpp +++ b/Rapfi/command/database.cpp @@ -310,9 +310,9 @@ void Command::database(int argc, char *argv[]) is >> ruleStr >> boardWidth >> boardHeight >> posStr; try { - if (boardWidth < 5 || boardWidth > ACTUAL_BOARD_SIZE) + if (boardWidth < 5 || boardWidth > MAX_BOARD_SIZE) throw std::invalid_argument("board width out of range [5,22]"); - if (boardHeight < 5 || boardHeight > ACTUAL_BOARD_SIZE) + if (boardHeight < 5 || boardHeight > MAX_BOARD_SIZE) throw std::invalid_argument("board height out of range [5,22]"); if (boardWidth != boardHeight) throw std::invalid_argument( diff --git a/Rapfi/command/gomocup.cpp b/Rapfi/command/gomocup.cpp index 7754f55..2985578 100644 --- a/Rapfi/command/gomocup.cpp +++ b/Rapfi/command/gomocup.cpp @@ -560,7 +560,7 @@ void start() { int boardSize; std::cin >> boardSize; - if (boardSize < 5 || boardSize > ACTUAL_BOARD_SIZE) { + if (boardSize < 5 || boardSize > MAX_BOARD_SIZE) { ERRORL("Unsupported board size!"); return; } diff --git a/Rapfi/command/opengen.cpp b/Rapfi/command/opengen.cpp index 1c0090d..daa66f0 100644 --- a/Rapfi/command/opengen.cpp +++ b/Rapfi/command/opengen.cpp @@ -115,7 +115,7 @@ void Command::opengen(int argc, char *argv[]) if (numOpenings < 1) throw std::invalid_argument("there must be at least one opening to generate"); - if (boardsize < 5 || boardsize > ACTUAL_BOARD_SIZE) + if (boardsize < 5 || boardsize > MAX_BOARD_SIZE) throw std::invalid_argument("boardsize must be in range [5,22]"); } catch (const std::exception &e) { diff --git a/Rapfi/core/pos.h b/Rapfi/core/pos.h index 145c4ca..b776ff0 100644 --- a/Rapfi/core/pos.h +++ b/Rapfi/core/pos.h @@ -25,11 +25,16 @@ // ------------------------------------------------- // Board size & limits -constexpr int FULL_BOARD_SIZE = 32; -constexpr int BOARD_BOUNDARY = 5; +/// Full board size. We use uint64_t bitboard and each cell takes 2 bits. +constexpr int FULL_BOARD_SIZE = 32; +/// Full board array size. This also counts all boundary cells. constexpr int FULL_BOARD_CELL_COUNT = FULL_BOARD_SIZE * FULL_BOARD_SIZE; -constexpr int ACTUAL_BOARD_SIZE = FULL_BOARD_SIZE - 2 * BOARD_BOUNDARY; -constexpr int MAX_MOVES = ACTUAL_BOARD_SIZE * ACTUAL_BOARD_SIZE; +/// Reserved boundary for branchless query in Board class implementation. +constexpr int BOARD_BOUNDARY = 5; +/// The actual maximum board size we can use. +constexpr int MAX_BOARD_SIZE = FULL_BOARD_SIZE - 2 * BOARD_BOUNDARY; +/// The maximum possible moves on an empty board (including a PASS). +constexpr int MAX_MOVES = MAX_BOARD_SIZE * MAX_BOARD_SIZE + 1; // ------------------------------------------------- @@ -46,7 +51,7 @@ struct Pos constexpr int y() const { return (_pos >> 5) - BOARD_BOUNDARY; } constexpr operator int() const { return _pos; } inline bool valid() const { return _pos >= PASS._pos && _pos < FULL_BOARD_END._pos; } - inline int moveIndex() const { return y() * ACTUAL_BOARD_SIZE + x(); } + inline int moveIndex() const { return y() * MAX_BOARD_SIZE + x(); } inline bool isInBoard(int boardWidth, int boardHeight) const; static int distance(Pos p1, Pos p2); diff --git a/Rapfi/database/yxdbstorage.cpp b/Rapfi/database/yxdbstorage.cpp index d0778e8..a687264 100644 --- a/Rapfi/database/yxdbstorage.cpp +++ b/Rapfi/database/yxdbstorage.cpp @@ -247,7 +247,7 @@ void YXDBStorage::load(std::istream &is, bool ignoreCorrupted) } int boardXLen = byteBuffer[1], boardYLen = byteBuffer[2]; - if ((unsigned)boardXLen > ACTUAL_BOARD_SIZE || (unsigned)boardYLen > ACTUAL_BOARD_SIZE) { + if ((unsigned)boardXLen > MAX_BOARD_SIZE || (unsigned)boardYLen > MAX_BOARD_SIZE) { if (ignoreCorrupted) continue; throw DBStorageCorruptedRecordError(filePath.string(), diff --git a/Rapfi/eval/evaluator.h b/Rapfi/eval/evaluator.h index e3e19a3..dd51a85 100644 --- a/Rapfi/eval/evaluator.h +++ b/Rapfi/eval/evaluator.h @@ -96,10 +96,14 @@ class PolicyBuffer private: inline size_t posToIndex(Pos pos) const { - size_t index = boardWidth * pos.y() + pos.x(); - assert(0 <= pos.x() && pos.x() < boardWidth); - assert(index < bufferSize); - return index; + if (pos == Pos::PASS) + return MAX_MOVES - 1; + else { + size_t index = boardWidth * pos.y() + pos.x(); + assert(0 <= pos.x() && pos.x() < boardWidth); + assert(index < bufferSize); + return index; + } } int boardWidth; diff --git a/Rapfi/game/board.cpp b/Rapfi/game/board.cpp index adce11b..0af6b39 100644 --- a/Rapfi/game/board.cpp +++ b/Rapfi/game/board.cpp @@ -63,7 +63,7 @@ Board::Board(int boardSize, CandidateRange candRange) , evaluator_(nullptr) , thisThread_(nullptr) { - assert(0 < boardSize && boardSize <= ACTUAL_BOARD_SIZE); + assert(0 < boardSize && boardSize <= MAX_BOARD_SIZE); stateInfos = new StateInfo[1 + boardCellCount * 2] {}; updateCache = new UpdateCache[1 + boardCellCount * 2]; diff --git a/Rapfi/game/board.h b/Rapfi/game/board.h index a448702..32fc2e8 100644 --- a/Rapfi/game/board.h +++ b/Rapfi/game/board.h @@ -155,7 +155,7 @@ class Board enum class MoveType { NORMAL, NO_EVALUATOR, NO_EVAL, NO_EVAL_MULTI }; /// Creates a board with board size and condidate range. - /// @param boardSize Size of the board, in range [0,ACTUAL_BOARD_SIZE]. + /// @param boardSize Size of the board, in range [1, MAX_BOARD_SIZE]. explicit Board(int boardSize, CandidateRange candRange = Config::DefaultCandidateRange); /// Clone a board object from other board and bind a search thread to it. /// @param other Board object to clone from. diff --git a/Rapfi/search/movepick.cpp b/Rapfi/search/movepick.cpp index d492376..f7c860f 100644 --- a/Rapfi/search/movepick.cpp +++ b/Rapfi/search/movepick.cpp @@ -359,8 +359,8 @@ Pos MovePicker::operator()() : generateNeighbors)(board, curMove, selfLast, - RANGE_SQUARE2_LINE4, - arraySize(RANGE_SQUARE2_LINE4)); + RANGE_SQUARE3_LINE4, + arraySize(RANGE_SQUARE3_LINE4)); } scoreAllMoves(); diff --git a/Rapfi/tuning/tuner.h b/Rapfi/tuning/tuner.h index 1f49875..c08581b 100644 --- a/Rapfi/tuning/tuner.h +++ b/Rapfi/tuning/tuner.h @@ -144,7 +144,7 @@ struct TuningConfig bool tuneRule[RULE_NB] = {}; uint8_t boardSizeMin = 5; - uint8_t boardSizeMax = ACTUAL_BOARD_SIZE; + uint8_t boardSizeMax = MAX_BOARD_SIZE; uint16_t minPly = 1; uint16_t minPlyBeforeFull = 50;