Esempio n. 1
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);
        }
Esempio n. 2
0
        private static bool CanForward(
            Color pawnColor,
            Board board,
            Square from, Square to)
        {
            // white: a1 -> a2; from.y - to.y == 1; from.x == to.x
            // black: a2 -> a1; from.y - to.y == -1; from.x == to.x
            var step = GetPawnStep(pawnColor);

            return
                (MoveProperty.DeltaX(from, to) == 0 &&
                 MoveProperty.DeltaY(from, to) == step &&
                 board[to].IsNone());
        }
Esempio n. 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);
        }
Esempio n. 4
0
        private static bool CanPush(
            Color pawnColor,
            Board board,
            Square from, Square to)
        {
            // white: a2 -> a4; from.y - to.y == 2; from.x == to.x
            // black: a7 -> a5; from.y - to.y == -2; from.x == to.x
            var row  = GetPawnStartRow(pawnColor);
            var step = GetPawnStep(pawnColor);

            return
                (row == from.Y &&
                 board[to].IsNone() &&
                 board[new Square(from.X, from.Y + step)].IsNone() &&
                 MoveProperty.DeltaX(from, to) == 0 &&
                 MoveProperty.DeltaY(from, to) == 2 * step);
        }