public int AttackedBySquare(bool sideToMove, int[] board, int squareInQuestion) { var imaginaryKnight = new Knight(board, squareInQuestion, sideToMove); var listOfAttackingSquares = imaginaryKnight.MoveGeneration(); foreach (var square in listOfAttackingSquares) { if (board[square] == Definitions.WhiteKnight || board[square] == Definitions.BlackKnight) { return(square); } } var imaginaryBishop = new Bishop(board, squareInQuestion, sideToMove); var listOfBishopMoves = imaginaryBishop.MoveGeneration(); foreach (var possibleAttackedFromSquare in listOfBishopMoves) { if (board[possibleAttackedFromSquare] == Definitions.WhiteQueen || board[possibleAttackedFromSquare] == Definitions.BlackQueen || board[possibleAttackedFromSquare] == Definitions.WhiteBishop || board[possibleAttackedFromSquare] == Definitions.BlackBishop) { return(possibleAttackedFromSquare); } } var imaginaryKing = new King(board, squareInQuestion, sideToMove); var listOfKingMoves = imaginaryKing.MoveGeneration(); foreach (var possibleAttackedFromSquare in listOfKingMoves) { if (board[possibleAttackedFromSquare] == Definitions.WhiteKing || board[possibleAttackedFromSquare] == Definitions.BlackKing) { return(possibleAttackedFromSquare); } } if (sideToMove == Definitions.WhiteToMove) { // Check if black has pawns that can attack us. if (board[squareInQuestion + 11] == Definitions.BlackPawn) { return(squareInQuestion + 11); } if (board[squareInQuestion + 9] == Definitions.BlackPawn) { return(squareInQuestion + 9); } } else { // Check if white has pawns that can attack us. if (board[squareInQuestion - 11] == Definitions.WhitePawn) { return(squareInQuestion - 11); } if (board[squareInQuestion - 9] == Definitions.WhitePawn) { return(squareInQuestion - 9); } } var imaginaryRook = new Rook(board, squareInQuestion, sideToMove); var listOfRookMoves = imaginaryRook.MoveGeneration(); foreach (var possibleAttackedFromSquares in listOfRookMoves) { if (board[possibleAttackedFromSquares] == Definitions.WhiteQueen || board[possibleAttackedFromSquares] == Definitions.BlackQueen || board[possibleAttackedFromSquares] == Definitions.WhiteRook || board[possibleAttackedFromSquares] == Definitions.BlackRook) { return(possibleAttackedFromSquares); } } return(99); }
public bool DoubleCheckedFen(int[] board, bool sideToMove, int[] kingSquare) { var possibleDoubleCheck = false; #region white side if (sideToMove == Definitions.White) { var whiteKnight = new Knight(board, kingSquare[1], Definitions.White); var listOfWhiteMoves = whiteKnight.MoveGeneration(); foreach (var square in listOfWhiteMoves) { if (board[square] == Definitions.BlackKnight) { possibleDoubleCheck = true; break; } } if (!possibleDoubleCheck) { return(false); } var whiteBishop = new Bishop(board, kingSquare[1], Definitions.White); listOfWhiteMoves = whiteBishop.MoveGeneration(); foreach (var square in listOfWhiteMoves) { if (board[square] == Definitions.BlackBishop) { return(true); } } var whiteRook = new Rook(board, kingSquare[1], Definitions.White); listOfWhiteMoves = whiteRook.MoveGeneration(); foreach (var square in listOfWhiteMoves) { if (board[square] == Definitions.BlackRook) { return(true); } } } #endregion #region black side else { var blackKnight = new Knight(board, kingSquare[0], Definitions.Black); var listOfBlackMoves = blackKnight.MoveGeneration(); foreach (var square in listOfBlackMoves) { if (board[square] == Definitions.WhiteKnight) { possibleDoubleCheck = true; break; } } if (!possibleDoubleCheck) { return(false); } var blackBishop = new Bishop(board, kingSquare[0], Definitions.Black); listOfBlackMoves = blackBishop.MoveGeneration(); foreach (var square in listOfBlackMoves) { if (board[square] == Definitions.WhiteBishop) { return(true); } } var blackRook = new Rook(board, kingSquare[0], Definitions.Black); listOfBlackMoves = blackRook.MoveGeneration(); foreach (var square in listOfBlackMoves) { if (board[square] == Definitions.WhiteRook) { return(true); } } } #endregion return(false); }