public static MoveSummary CanKnightMove(Board board, Square from, Square to) { var isSameColor = board[from].Color == board[to].Color; var isCapturing = board[to].IsNone() ? false : !isSameColor; var isMovePossible = !isSameColor && MoveProperty.AbsDeltaX(from, to) * MoveProperty.AbsDeltaY(from, to) == 2; return(MoveSummaryBuilder.DefaultMoveSummary(isCapturing, isMovePossible, to)); }
public static MoveSummary CanBishopMove(Board board, Square from, Square to) { var isSameColor = board[from].Color == board[to].Color; var isCapturing = board[to].IsNone() ? false : !isSameColor; var isMovePossible = !isSameColor && Checker.CanMoveLineary( MoveProperty.IsDiagonalLine(from, to), board, from, to); return(MoveSummaryBuilder.DefaultMoveSummary(isCapturing, isMovePossible, to)); }
private static MoveSummary CanCastle(ChessGame game, Color kingColor, Board board, Square from, Square to) { var isHorizontalLine = MoveProperty.IsHorizontalLine(from, to); if (isHorizontalLine) { var isAnyPieceBetween = Checker.IsAnyPieceBetween(board, from, to); if (!isAnyPieceBetween) { var isKingWhite = kingColor.IsWhite(); var hasKingMoved = isKingWhite ? game.HasWhiteKingMoved : game.HasBlackKingMoved; if (hasKingMoved) { return (MoveSummaryBuilder.DefaultMoveSummary(false, false, Square.NoneSquare)); } var kingStartSquare = GetKingStartSquare(isKingWhite); if (kingStartSquare == from) { var isQueensideDirection = IsQueensideDirection(isKingWhite, to); var isKingsideDirection = IsKingsideDirection(isKingWhite, to); Square rookStartSquare; bool hasRookMoved; if (isQueensideDirection) { rookStartSquare = GetQueensideRookStartSquare(isKingWhite); hasRookMoved = isKingWhite ? game.HasWhiteQueensideRookMoved : game.HasBlackQueensideRookMoved; } else if (isKingsideDirection) { rookStartSquare = GetKingsideRookStartSquare(isKingWhite); hasRookMoved = isKingWhite ? game.HasWhiteKingsideRookMoved : game.HasBlackKingsideRookMoved; } else { return(MoveSummaryBuilder.DefaultMoveSummary(false, false, Square.NoneSquare)); } var piece = board[rookStartSquare]; if (piece.IsNone()) { return (MoveSummaryBuilder.DefaultMoveSummary(false, false, Square.NoneSquare)); } var isValid = !hasRookMoved && piece.Color == kingColor && piece.Type == PieceType.Rook; if (isValid) { return(MoveSummaryBuilder. KingSummary(false, true, isQueensideDirection, isKingsideDirection, Square.NoneSquare)); } } } } return(MoveSummaryBuilder.DefaultMoveSummary(false, false, Square.NoneSquare)); }