From 7b5e1a2f2bdcb7244ffae5e4810f18d04c076441 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 20 Sep 2020 18:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20in=5Fhow=5Fmany=5Fmills()?= =?UTF-8?q?=20=E4=B8=AD=E5=BD=93=20c=20=E4=B8=BA=20NOBODY=20=E6=97=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提交 1d7ecd668073943a2a59edea7c61c37a74b3d485 对 in_how_many_mills() 函数的开头 if (player == PLAYER_NOBODY) { player = locationToPlayer(square); } 修改为: if (c == NOBODY) { c = Color(locationToColor(square) >> PLAYER_SHIFT); } 不符合本意。导致 c 变成 NO_COLOR。 现在更正之。 并全面消除 PLAYER_SHIFT (4) 和修改前对战700盘,胜率误差6%,可认为对胜率无影响,并且对自对弈效率也无影响。 --- src/movegen.cpp | 4 ++-- src/position.cpp | 20 ++++++++++---------- src/types.h | 10 ++++++---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index 20f1421b..90763f58 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -360,7 +360,7 @@ ExtMove *generate(Position &position, ExtMove *moveList) if (position.is_all_in_mills(them)) { for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) { s = MoveList::movePriorityTable[i]; - if (position.board[s]& (them << PLAYER_SHIFT)) { + if (position.board[s]& make_piece(them)) { *cur++ = (Move)-s; } } @@ -370,7 +370,7 @@ ExtMove *generate(Position &position, ExtMove *moveList) // not is all in mills for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) { s = MoveList::movePriorityTable[i]; - if (position.board[s] & (them << PLAYER_SHIFT)) { + if (position.board[s] & make_piece(them)) { if (rule.allowRemovePieceInMill || !position.in_how_many_mills(s, NOBODY)) { *cur++ = (Move)-s; } diff --git a/src/position.cpp b/src/position.cpp index 8a42cb09..7202ef55 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -628,7 +628,7 @@ bool Position::put_piece(Square s, bool updateCmdlist) } if (phase == PHASE_PLACING) { - piece = (Piece)((0x01 | (sideToMove << PLAYER_SHIFT)) + rule.nTotalPiecesEachSide - pieceCountInHand[us]); + piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - pieceCountInHand[us]); pieceCountInHand[us]--; pieceCountOnBoard[us]++; @@ -746,7 +746,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist) return false; // if piece is not their - if (!((them << PLAYER_SHIFT) & board[s])) + if (!(make_piece(them) & board[s])) return false; if (!rule.allowRemovePieceInMill && @@ -825,7 +825,7 @@ bool Position::select_piece(Square s) if (action != ACTION_SELECT && action != ACTION_PLACE) return false; - if (board[s] & (sideToMove << PLAYER_SHIFT)) { + if (board[s] & make_piece(sideToMove)) { currentSquare = s; action = ACTION_PLACE; @@ -1093,7 +1093,7 @@ inline Key Position::update_key(Square s) int pieceType = color_on(s); // TODO: this is std, but current code can work //Location loc = board[s]; - //int pieceType = loc == 0x0f? 3 : loc >> PLAYER_SHIFT; + //int pieceType = loc == 0x0f? 3 : loc >> 4; st->key ^= Zobrist::psq[pieceType][s]; @@ -1335,7 +1335,7 @@ void Position::create_mill_table() Color Position::color_on(Square s) const { - return Color((board[s] & 0x30) >> PLAYER_SHIFT); + return color_of(board[s]); } int Position::in_how_many_mills(Square s, Color c, Square squareSelected) @@ -1344,7 +1344,7 @@ int Position::in_how_many_mills(Square s, Color c, Square squareSelected) Piece locbak = NO_PIECE; if (c == NOBODY) { - c = Color(color_on(s) >> PLAYER_SHIFT); + c = color_on(s); } if (squareSelected != SQ_0) { @@ -1353,7 +1353,7 @@ int Position::in_how_many_mills(Square s, Color c, Square squareSelected) } for (int l = 0; l < LD_NB; l++) { - if ((c << PLAYER_SHIFT) & + if (make_piece(c) & board[millTable[s][l][0]] & board[millTable[s][l][1]]) { n++; @@ -1380,7 +1380,7 @@ int Position::add_mills(Square s) idx[2] = millTable[s][i][1]; // no mill - if (!((m << PLAYER_SHIFT) & board[idx[1]] & board[idx[2]])) { + if (!(make_piece(m) & board[idx[1]] & board[idx[2]])) { continue; } @@ -1436,7 +1436,7 @@ int Position::add_mills(Square s) bool Position::is_all_in_mills(Color c) { for (Square i = SQ_BEGIN; i < SQ_END; i = static_cast(i + 1)) { - if (board[i] & ((uint8_t)(c << PLAYER_SHIFT))) { + if (board[i] & ((uint8_t)make_piece(c))) { if (!in_how_many_mills(i, NOBODY)) { return false; } @@ -1491,7 +1491,7 @@ void Position::surrounded_pieces_count(Square s, int &nOurPieces, int &nTheirPie nBanned++; break; default: - if (sideToMove == pieceType >> PLAYER_SHIFT) { + if (color_of(pieceType) == sideToMove) { nOurPieces++; } else { nTheirPieces++; diff --git a/src/types.h b/src/types.h index 6323bfce..f4a0cf5b 100644 --- a/src/types.h +++ b/src/types.h @@ -136,8 +136,6 @@ enum Color : uint8_t NOBODY = 8 }; -#define PLAYER_SHIFT 4 - enum Phase : uint16_t { PHASE_NONE = 0, @@ -445,10 +443,15 @@ constexpr Square make_square(File file, Rank rank) return Square((file << 3) + rank - 1); } +constexpr Piece make_piece(Color c) +{ + return Piece(c << 4); +} + constexpr Piece make_piece(Color c, PieceType pt) { if (pt == BLACK_STONE || pt == WHITE_STONE) { - return Piece((c << 4)); + return make_piece(c); } if (pt == BAN) { @@ -473,7 +476,6 @@ constexpr PieceType type_of(Piece pc) inline Color color_of(Piece pc) { - assert(pc != NO_PIECE); return Color(pc >> 4); }