private void updateSelectionSquare() { //special case to draw the selected square if there is one if (selectionMade) { dgv_chessBoard[selectedX, selectedY].Value = Chess.Properties.Resources.BlueSquare; //Highlights the selected object } else { ChessPiece updatePiece = chessBoard[selectedX, selectedY]; displayPieceAt(updatePiece.PositionX, updatePiece.PositionY, updatePiece.Type(), updatePiece.Colour); } //Make sure that we can't override what the main player is trying to select if (!(opponentSelX == selectedX && opponentSelY == selectedY)) { if (opponentSelMade) { dgv_chessBoard[opponentSelX, opponentSelY].Value = Chess.Properties.Resources.Orange; //Highlights the object the opponent is selecting } else { ChessPiece updatePiece = chessBoard[opponentSelX, opponentSelY]; displayPieceAt(updatePiece.PositionX, updatePiece.PositionY, updatePiece.Type(), updatePiece.Colour); } } }
//Returns true if the piece is a king or rook public static bool isCastling(ChessPiece firstPiece, ChessPiece secondPiece, ChessPiece[,] chessBoard) { bool retVal = false; //Check that we're dealing with a King and a Rook, and that they're the same colour if (((firstPiece.Type() == chessPieces.KING && secondPiece.Type() == chessPieces.ROOK) || (secondPiece.Type() == chessPieces.KING && firstPiece.Type() == chessPieces.ROOK)) && secondPiece.Colour == firstPiece.Colour) { //Check that the pieces can Castle if (firstPiece.CanCastle && secondPiece.CanCastle) { bool emptySpace = true; //check that there is empty space between the king and rook int max; int min; if (firstPiece.PositionX > secondPiece.PositionX) { max = firstPiece.PositionX; min = secondPiece.PositionX; } else { max = secondPiece.PositionX; min = firstPiece.PositionX; } for (int i = min + 1; i < max; i++) { if (chessBoard[i, firstPiece.PositionY].Type() != chessPieces.CLEAR) { emptySpace = false; } } if (emptySpace) { retVal = true; } } } return(retVal); }