From afcc4a953d6bab9f01d5b354eda143d1acdf80ee Mon Sep 17 00:00:00 2001 From: Calcitem Date: Mon, 28 Dec 2020 21:19:42 +0800 Subject: [PATCH] Use EFFECTIVE_SQUARE_NB --- src/evaluate.cpp | 3 +-- src/movegen.cpp | 13 +++---------- src/movegen.h | 6 +++++- src/position.cpp | 8 ++++---- src/ui/qt/boarditem.cpp | 2 +- src/ui/qt/boarditem.h | 2 +- 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 68debcd6..6c146441 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -121,8 +121,7 @@ Value Evaluation::value() break; case PHASE_GAMEOVER: - if (pos.pieces_count_on_board(BLACK) + pos.pieces_count_on_board(WHITE) >= - RANK_NB * FILE_NB) { + if (pos.pieces_count_on_board(BLACK) + pos.pieces_count_on_board(WHITE) >= EFFECTIVE_SQUARE_NB) { if (rule.isBlackLoseButNotDrawWhenBoardFull) { value -= VALUE_MATE; } else { diff --git a/src/movegen.cpp b/src/movegen.cpp index db32c55f..1253eb78 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -51,13 +51,10 @@ template<> ExtMove *generate(Position &pos, ExtMove *moveList) { Square newSquare, oldSquare; - - const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB; - ExtMove *cur = moveList; // move piece that location weak first - for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) { + for (int i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) { oldSquare = MoveList::movePriorityTable[i]; if (!pos.select_piece(oldSquare)) { @@ -97,12 +94,10 @@ ExtMove *generate(Position &pos, ExtMove *moveList) Color us = pos.side_to_move(); Color them = ~us; - const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB; - ExtMove *cur = moveList; if (pos.is_all_in_mills(them)) { - for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) { + for (int i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) { s = MoveList::movePriorityTable[i]; if (pos.get_board()[s] & make_piece(them)) { *cur++ = (Move)-s; @@ -112,7 +107,7 @@ ExtMove *generate(Position &pos, ExtMove *moveList) } // not is all in mills - for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) { + for (int i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) { s = MoveList::movePriorityTable[i]; if (pos.get_board()[s] & make_piece(them)) { if (rule.allowRemovePieceInMill || !pos.in_how_many_mills(s, NOBODY)) { @@ -129,8 +124,6 @@ ExtMove *generate(Position &pos, ExtMove *moveList) template<> ExtMove *generate(Position &pos, ExtMove *moveList) { - const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB; - ExtMove *cur = moveList; switch (pos.get_action()) { diff --git a/src/movegen.h b/src/movegen.h index 9c825b4e..9a5dda6a 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -69,18 +69,22 @@ struct MoveList explicit MoveList(/* const */ Position &pos) : last(generate(pos, moveList)) { } + const ExtMove *begin() const { return moveList; } + const ExtMove *end() const { return last; } + size_t size() const { return last - moveList; } + bool contains(Move move) const { return std::find(begin(), end(), move) != end(); @@ -89,7 +93,7 @@ struct MoveList static void create(); static void shuffle(); - inline static std::array movePriorityTable { + inline static std::array movePriorityTable { SQ_8, SQ_9, SQ_10, SQ_11, SQ_12, SQ_13, SQ_14, SQ_15, SQ_16, SQ_17, SQ_18, SQ_19, SQ_20, SQ_21, SQ_22, SQ_23, SQ_24, SQ_25, SQ_26, SQ_27, SQ_28, SQ_29, SQ_30, SQ_31, diff --git a/src/position.cpp b/src/position.cpp index 9a22409a..4b2a5381 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1154,7 +1154,7 @@ bool Position::check_gameover_condition() return true; } - if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= RANK_NB * FILE_NB) { + if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) { if (rule.isBlackLoseButNotDrawWhenBoardFull) { set_gameover(WHITE, LOSE_REASON_BOARD_IS_FULL); } else { @@ -1756,7 +1756,7 @@ void Position::surrounded_pieces_count(Square s, int &nOurPieces, int &nTheirPie bool Position::is_all_surrounded() const { // Full - if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= RANK_NB * FILE_NB) + if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) return true; // Can fly @@ -1966,8 +1966,8 @@ void Position::turn(vector &cmdlist, bool cmdChange /*= true*/) for (r = 0; r < RANK_NB; r++) { ch = board[RANK_NB + r]; - board[RANK_NB + r] = board[RANK_NB * FILE_NB + r]; - board[RANK_NB * FILE_NB + r] = ch; + board[RANK_NB + r] = board[EFFECTIVE_SQUARE_NB + r]; + board[EFFECTIVE_SQUARE_NB + r] = ch; } reset_bb(); diff --git a/src/ui/qt/boarditem.cpp b/src/ui/qt/boarditem.cpp index a43ca0e6..7fad3c8a 100644 --- a/src/ui/qt/boarditem.cpp +++ b/src/ui/qt/boarditem.cpp @@ -177,7 +177,7 @@ QPointF BoardItem::polar2pos(File file, Rank rank) bool BoardItem::pos2polar(QPointF pos, File &file, Rank &rank) { // 寻找最近的落子点 - for (int i = 0; i < FILE_NB * RANK_NB; i++) { + for (int i = 0; i < EFFECTIVE_SQUARE_NB; i++) { // 如果pos点在落子点附近 if (QLineF(pos, position[i]).length() < PIECE_SIZE / 6) { file = File(i / RANK_NB + 1); diff --git a/src/ui/qt/boarditem.h b/src/ui/qt/boarditem.h index 1648ab41..df324bae 100644 --- a/src/ui/qt/boarditem.h +++ b/src/ui/qt/boarditem.h @@ -75,7 +75,7 @@ private: int sizeShadow {5}; // 24个落子点 - QPointF position[FILE_NB * RANK_NB]; + QPointF position[EFFECTIVE_SQUARE_NB]; // 是否有斜线 bool hasObliqueLine {false};