public static MoveSummary CanRookMove(Board board, Square from, Square to) { //throw new NotImplementedException("CanRookMove"); var piece = board[from]; var isSameColor = board[from].Color == board[to].Color; var isCapturing = board[to].IsNone() ? false : !isSameColor; var isMovePossible = !isSameColor && Checker.CanMoveLineary( MoveProperty.IsHorizontalLine(from, to) || MoveProperty.IsVerticalLine(from, to), board, from, to); var isWhite = piece.Color.IsWhite(); var startQueensideSquare = isWhite ? WhiteCastlingSquares.QueensideRookStartSquare : BlackCastlingSquares.QueensideRookStartSquare; var startKingsideSquare = isWhite ? WhiteCastlingSquares.KingsideRookStartSquare : BlackCastlingSquares.KingsideRookStartSquare; var isQueensideRookMoving = from == startQueensideSquare; var isKingsideRookMoving = from == startKingsideSquare; return(MoveSummaryBuilder.RookSummary( isCapturing, isMovePossible, isQueensideRookMoving, isKingsideRookMoving, to)); }
public static MoveSummary CanQueenMove(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.IsHorizontalLine(from, to) || MoveProperty.IsVerticalLine(from, to) || 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)); }