コード例 #1
0
        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));
        }
コード例 #2
0
        private static bool CanCapture(
            Color pawnColor,
            Board board,
            Square from, Square to)
        {
            // white: b2 -> a3 || c3; from.y - to.y == 1; |from.x - to.x| == 1
            // black: b7 -> a6 || c6; from.y - to.y == -1; |from.x == to.x| == 1
            var step = GetPawnStep(pawnColor);

            return
                (!board[to].IsNone() &&
                 MoveProperty.AbsDeltaX(from, to) == 1 &&
                 MoveProperty.DeltaY(from, to) == step);
        }
コード例 #3
0
        private static bool CanEnPassantCapture(
            ChessGame game,
            Color pawnColor,
            Square from, Square to)
        {
            if (game.EnPassantTargetSquare.IsNone())
            {
                return(false);
            }

            var step = GetPawnStep(pawnColor);

            return
                (to == game.EnPassantTargetSquare &&
                 MoveProperty.AbsDeltaX(from, to) == 1 &&
                 MoveProperty.DeltaY(from, to) == step);
        }
コード例 #4
0
 private static bool CanDefaultMove(Square from, Square to, bool isSameColor) =>
 !isSameColor &&
 MoveProperty.AbsDeltaX(from, to) <= 1 &&
 MoveProperty.AbsDeltaY(from, to) <= 1;