refactor: inHowManyMills() 函数由重载改为单一函数
This commit is contained in:
parent
d47be83ae5
commit
c84db35655
|
@ -150,7 +150,7 @@ int StateInfo::generateMoves(Stack<move_t, MOVE_COUNT> &moves)
|
|||
for (int i = Board::MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
square = static_cast<square_t>(MoveList::movePriorityTable[i]);
|
||||
if (boardLocations[square] & opponent) {
|
||||
if (rule.allowRemoveMill || !position->board.inHowManyMills(square)) {
|
||||
if (rule.allowRemoveMill || !position->board.inHowManyMills(square, PLAYER_NOBODY)) {
|
||||
moves.push_back((move_t)-square);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,25 +197,14 @@ square_t Board::polarToSquare(int r, int s)
|
|||
return static_cast<square_t>(r * N_SEATS + s - 1);
|
||||
}
|
||||
|
||||
int Board::inHowManyMills(square_t square)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
for (int l = 0; l < LINE_TYPES_COUNT; l++) {
|
||||
if ((locations[square] & 0x30) &
|
||||
locations[millTable[square][l][0]] &
|
||||
locations[millTable[square][l][1]]) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int Board::inHowManyMills(square_t square, player_t player)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (player == PLAYER_NOBODY) {
|
||||
player = player_t(locations[square] & 0x30);
|
||||
}
|
||||
|
||||
for (int l = 0; l < LINE_TYPES_COUNT; l++) {
|
||||
if (player &
|
||||
locations[millTable[square][l][0]] &
|
||||
|
@ -306,7 +295,7 @@ bool Board::isAllInMills(player_t player)
|
|||
{
|
||||
for (square_t i = SQ_BEGIN; i < SQ_END; i = static_cast<square_t>(i + 1)) {
|
||||
if (locations[i] & (uint8_t)player) {
|
||||
if (!inHowManyMills(i)) {
|
||||
if (!inHowManyMills(i, PLAYER_NOBODY)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,6 @@ public:
|
|||
void rotate(int degrees, vector<string> &cmdlist, char *cmdline, int32_t move_, square_t square, bool cmdChange = true);
|
||||
|
||||
// 判断棋盘 square 处的棋子处于几个“三连”中
|
||||
int inHowManyMills(square_t square);
|
||||
int inHowManyMills(square_t square, player_t player);
|
||||
|
||||
// 判断玩家的所有棋子是否都处于“三连”状态
|
||||
|
|
|
@ -573,7 +573,7 @@ bool StateInfo::capture(square_t square, int8_t updateCmdlist)
|
|||
|
||||
// 如果当前子是否处于“三连”之中,且对方还未全部处于“三连”之中
|
||||
if (!rule.allowRemoveMill &&
|
||||
position->board.inHowManyMills(square) &&
|
||||
position->board.inHowManyMills(square, PLAYER_NOBODY) &&
|
||||
!position->board.isAllInMills(opponent)) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue