示例#1
0
bool ChessMove::IsValidCastleMove(const ChessBoard& board) const{
    ChessPiece* king = board.GetPiece(startX, startY);
    if (king->GetMoveCount() != 0) return false;
    if (abs(startX-endX) != 2 || startY != endY) return false;
    int x = 7;
    int delta = 1;
    if (startX > endX){
        x = 0;
        delta = -1;
    }
    ChessPiece* rook = board.GetPiece(x, startY);
    if (rook && rook->GetMoveCount() != 0) return false;
    ChessColor opposingColor = SwitchColor(king->GetColor());
    for (int i = startX; GetCondition(i, startX, x); i += delta){
        if ((board.GetPiece(i, startY) && i != startX)
          || board.UnderAttack(opposingColor,i,startY)) return false;
    }
    return true;
}
示例#2
0
void MainWindow::SwitchTurns(){
    startPiece = NULL;
    currentPlayer = SwitchColor(currentPlayer);
}