private static void GetKingCastlingPosition(ChessBoard board, char file, sbyte rank, List <ChessBoard> result, Square current) { ChessBoard tempboard; if (WhiteKing.IsSafe(board) && DefaultInfo.WhiteKingIsUnMoved && DefaultInfo.WhiteHsideRookIsUnMoved) { char rookfile = 'h'; for (char tfile = file; tfile < 'h'; tfile++) { if (board[tfile, rank] == (sbyte)DefaultPieces.WhiteRook) { rookfile = tfile; } } tempboard = board.ShallowCopy(); bool CastlingAvailable = true; for (char tfile = file; tfile <= 'g'; tfile++) { if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.WhiteKing && board[tfile, rank] != (sbyte)DefaultPieces.WhiteRook) { CastlingAvailable = false; break; } } for (char tfile = rookfile; tfile >= 'f'; tfile--) { if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.WhiteKing && board[tfile, rank] != (sbyte)DefaultPieces.WhiteRook) { CastlingAvailable = false; break; } } for (char tfile = rookfile; tfile <= 'f'; tfile++) { if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.WhiteKing && board[tfile, rank] != (sbyte)DefaultPieces.WhiteRook) { CastlingAvailable = false; break; } } for (char tfile = file; tfile <= 'g'; tfile++) { ChessBoard temp2board = board.ShallowCopy(); temp2board[file, rank] = 0; temp2board[tfile, rank] = (sbyte)DefaultPieces.WhiteKing; if (!WhiteKing.IsSafe(temp2board)) { CastlingAvailable = false; break; } } if (CastlingAvailable) { tempboard = Piece.PerformMove(board, current, new Square('g', rank)); tempboard = Piece.PerformMove(tempboard, new Square(rookfile, rank), new Square('f', rank)); result.Add(tempboard); } } }
public static bool IsSafe(ChessBoard board) { ChessBoard tempboard = board.ShallowCopy(); tempboard.ReverseSides(); return(WhiteKing.IsSafe(tempboard)); }
// Code Review: Назваргументів методу повинні починатися з малої літери. public static List <ChessBoard> AddNewPosition(List <ChessBoard> ResultedPositionsList, ChessBoard position, bool IsWhite) { if (IsWhite && WhiteKing.IsSafe(position)) { ResultedPositionsList.Add(position); } else if (!IsWhite && BlackKing.IsSafe(position)) { ResultedPositionsList.Add(position); } return(ResultedPositionsList); }