diff --git a/src/ai/movegen.cpp b/src/ai/movegen.cpp index af7f8b8f..8c2f04ea 100644 --- a/src/ai/movegen.cpp +++ b/src/ai/movegen.cpp @@ -363,7 +363,7 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList) break; case ACTION_REMOVE: - opponent = Player::getOpponent(position->sideToMove); + opponent = ~position->sideToMove; if (position->board.isAllInMills(opponent)) { for (int i = Board::MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) { diff --git a/src/game/player.h b/src/game/player.h index 9f75b1fa..5116957e 100644 --- a/src/game/player.h +++ b/src/game/player.h @@ -50,11 +50,6 @@ public: } } - inline static Color getOpponent(Color c) - { - return c == BLACK ? WHITE : BLACK; - } - private: Color color; }; diff --git a/src/game/position.cpp b/src/game/position.cpp index 8bfb55d0..c6cbf73c 100644 --- a/src/game/position.cpp +++ b/src/game/position.cpp @@ -388,7 +388,7 @@ bool Position::removePiece(Square square, bool updateCmdlist) if (!rule.allowRemovePieceInMill && board.inHowManyMills(square, NOBODY) && - !board.isAllInMills(Player::getOpponent(sideToMove))) { + !board.isAllInMills(~sideToMove)) { return false; } @@ -509,7 +509,7 @@ bool Position::giveup(Color loser) char loserCh = Player::colorToCh(loserColor); string loserStr = Player::chToStr(loserCh); - winner = Player::getOpponent(loser); + winner = ~loser; tips = "玩家" + loserStr + "投子认负"; sprintf(cmdline, "Player%d give up!", loserColor); score[winner]++; @@ -661,9 +661,9 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist) for (int i = 1; i <= 2; i++) { if (elapsedSeconds[i] > rule.maxTimeLedToLose * 60) { elapsedSeconds[i] = rule.maxTimeLedToLose * 60; - winner = Player::getOpponent(Color(i)); + winner = ~Color(i); tips = "玩家" + Player::chToStr(Player::colorToCh(Color(i))) + "超时判负。"; - sprintf(cmdline, "Time over. Player%d win!", Player::getOpponent(Color(i))); + sprintf(cmdline, "Time over. Player%d win!", ~Color(i)); } } @@ -688,7 +688,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist) for (int i = 1; i <= 2; i++) { if (nPiecesOnBoard[i] + nPiecesInHand[i] < rule.nPiecesAtLeast) { - winner = Player::getOpponent(Color(i)); + winner = ~Color(i); phase = PHASE_GAMEOVER; if (updateCmdlist) { @@ -752,7 +752,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist) if (rule.isLoseButNotChangeTurnWhenNoWay) { if (updateCmdlist) { tips = "玩家" + Player::chToStr(chSide) + "无子可走被闷"; - winner = Player::getOpponent(sideToMove); + winner = ~sideToMove; sprintf(cmdline, "Player%d no way to go. Player%d win!", sideToMove, winner); cmdlist.emplace_back(string(cmdline)); // TODO: memleak } @@ -819,7 +819,7 @@ void Position::setSideToMove(Color c) chSide = Player::colorToCh(sideToMove); - opponent = Player::getOpponent(sideToMove); + opponent = ~sideToMove; chOpponent = Player::colorToCh(opponent); } @@ -830,7 +830,7 @@ Color Position::getSideToMove() void Position::changeSideToMove() { - setSideToMove(Player::getOpponent(sideToMove)); + setSideToMove(~sideToMove); } bool Position::doNullMove() @@ -964,7 +964,7 @@ Key Position::getNextPrimaryKey(Move m) MoveType mt = type_of(m); if (mt == MOVETYPE_REMOVE) { - int pieceType = Player::getOpponent(sideToMove); + int pieceType = ~sideToMove; npKey ^= zobrist[sq][pieceType]; if (rule.hasBannedLocations && phase == PHASE_PLACING) { diff --git a/src/game/types.h b/src/game/types.h index 203e27b2..f63d5fba 100644 --- a/src/game/types.h +++ b/src/game/types.h @@ -288,7 +288,7 @@ inline Value &operator-=(Value &v, int i) constexpr Color operator~(Color color) { - return Color(color ^ BLACK); // Toggle color + return Color(color ^ 3); // Toggle color } // constexpr Piece operator~(Piece p)