public bool IsKingInCheck(Side sideToCheck) { // Checks the moves of the opposing side bool inCheck = false; // Common sense dictates that there must be one and only one king on either side King kingToCheck = (King)GetPiecesOfTypeAndSide(typeof(King), sideToCheck).ToArray()[0]; foreach (AbstractPiece activePiece in this.activePieces) { if (activePiece.side != sideToCheck) { Bitboard availableMoves = activePiece.GetMovesForCurrentPosition(); if (availableMoves.ValueAtPosition(kingToCheck.GetCurrentPosition()) > 0) { // Special check for Pawns advancing forward - they are of no harm and must not be considered here if (activePiece.GetType().Name == Constants.PieceClassNames.Pawn && activePiece.GetCurrentPosition().GetColumn() == kingToCheck.GetCurrentPosition().GetColumn()) { // Laugh it off } else { // Be very scared inCheck = true; } } } } return(inCheck); }