From 3f299c8f2bea30bc55be3e881abcba584f0aa304 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 22 Mar 2020 21:58:21 +0800 Subject: [PATCH] =?UTF-8?q?board:=20=E6=96=B0=E5=A2=9E=20locationToPlayer(?= =?UTF-8?q?)=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game/board.cpp | 9 +++++++-- src/game/board.h | 6 ++++-- src/game/player.h | 2 +- src/game/position.cpp | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/game/board.cpp b/src/game/board.cpp index c7a8c943..41baed9f 100644 --- a/src/game/board.cpp +++ b/src/game/board.cpp @@ -195,12 +195,17 @@ square_t Board::polarToSquare(int r, int s) return static_cast(r * N_SEATS + s - 1); } +player_t Board::locationToPlayer(square_t square) +{ + return player_t(locations[square] & 0x30); +} + int Board::inHowManyMills(square_t square, player_t player) { int n = 0; if (player == PLAYER_NOBODY) { - player = player_t(locations[square] & 0x30); + player = locationToPlayer(square); } for (int l = 0; l < LINE_TYPES_COUNT; l++) { @@ -223,7 +228,7 @@ int Board::addMills(square_t square) uint64_t mill = 0; int n = 0; int idx[3], min, temp; - char m = locations[square] & 0x30; + player_t m = locationToPlayer(square); for (int i = 0; i < 3; i++) { idx[0] = square; diff --git a/src/game/board.h b/src/game/board.h index c8e8a913..6a8ba9bc 100644 --- a/src/game/board.h +++ b/src/game/board.h @@ -109,6 +109,8 @@ public: static void printBoard(); + player_t locationToPlayer(square_t square); + //private: // 棋局,抽象为一个 5*8 的数组,上下两行留空 @@ -117,8 +119,8 @@ public: 0x0F 代表禁点 0x11~0x1C 代表先手第 1~12 子 0x21~0x2C 代表后手第 1~12 子 - 判断棋子是先手的用 (locations[i] & 0x10) - 判断棋子是后手的用 (locations[i] & 0x20) + 判断棋子是先手的用 (locations[square] & 0x10) + 判断棋子是后手的用 (locations[square] & 0x20) */ location_t locations[SQ_EXPANDED_COUNT]{}; diff --git a/src/game/player.h b/src/game/player.h index 422fea34..74b00ade 100644 --- a/src/game/player.h +++ b/src/game/player.h @@ -43,7 +43,7 @@ public: inline static int toId(player_t player) { - return player == PLAYER_BLACK ? 1 : 2; + return player >> PLAYER_SHIFT; } inline static player_t idToPlayer(int id) diff --git a/src/game/position.cpp b/src/game/position.cpp index a9ae69a4..f8b2a516 100644 --- a/src/game/position.cpp +++ b/src/game/position.cpp @@ -1137,7 +1137,7 @@ hash_t StateInfo::updateHash(square_t square) // PieceType is boardLocations[square] // 0b00 表示空白,0b01 = 1 表示先手棋子,0b10 = 2 表示后手棋子,0b11 = 3 表示禁点 - int pieceType = (boardLocations[square] & 0x30) >> 4; + int pieceType = Player::toId(position->board.locationToPlayer(square)); // 清除或者放置棋子 position->hash ^= zobrist[square][pieceType];