Skip to content

Commit

Permalink
use RANGE_SQUARE3_LINE4 in qvcf
Browse files Browse the repository at this point in the history
test r15
  • Loading branch information
dhbloo committed Aug 1, 2024
1 parent dfe01a0 commit e5ddaf4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Rapfi/command/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Rapfi/command/gomocup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Rapfi/command/opengen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 10 additions & 5 deletions Rapfi/core/pos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// -------------------------------------------------

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Rapfi/database/yxdbstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 8 additions & 4 deletions Rapfi/eval/evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Rapfi/game/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 1 addition & 1 deletion Rapfi/game/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Rapfi/search/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ Pos MovePicker::operator()()
: generateNeighbors<VCF | COMB>)(board,
curMove,
selfLast,
RANGE_SQUARE2_LINE4,
arraySize(RANGE_SQUARE2_LINE4));
RANGE_SQUARE3_LINE4,
arraySize(RANGE_SQUARE3_LINE4));
}

scoreAllMoves<BALANCED>();
Expand Down
2 changes: 1 addition & 1 deletion Rapfi/tuning/tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e5ddaf4

Please sign in to comment.