board: 新增 locationToPlayer() 函数

This commit is contained in:
Calcitem 2020-03-22 21:58:21 +08:00
parent 907534d0c8
commit 3f299c8f2b
4 changed files with 13 additions and 6 deletions

View File

@ -195,12 +195,17 @@ square_t Board::polarToSquare(int r, int s)
return static_cast<square_t>(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;

View File

@ -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]{};

View File

@ -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)

View File

@ -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];