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); }
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()); }
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); }
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); }