Can the king catch the pawn?

Python 2, 53 40

lambda x,y,p,q:y-2<q>=abs(x-p)+q/7+y/8*5

The king has coordinates (x, y) and the pawn (p, q).

There are three significant cases:

  1. The pawn is on rank 7 and the king on rank 8. To capture the pawn, the king must be on the same file or an adjacent one.

    Result: q = 7 ⋀ y = 8 → |x - p| ≤ 1

  2. The pawn is on rank 7. To capture the pawn, the king must be within six files.

    Result: q = 7 → |x - p| ≤ 6

  3. The pawn is on a lower rank. To capture the pawn, the king must be able to reach the promotion square at most one move after the pawn.

    Result: q < 7 → |x - p| ≤ q ⋀ y - 1 ≤ q

My solution is just these conditions golfed down. Hopefully there aren't mistakes this time.


Jelly, 33 bytes

‘»Ɠ_2<®
Ɠ©<7
:5+Ɠ>7$¤<1.4
Ɠ_ƓA2£Ŀ

This program reads the coordinates as x2\nx1\ny2\ny1 from STDIN. Try it online!

Non-competing version

Unfortunately, the Jelly interpreter had a bug when this question was posted. Said bug prevented it from accepting more than two command-line arguments. The newest version of Jelly can solve the given task in 23 bytes.

⁶>7×5
_A+⁵>6$¤+¢’»⁶_2<⁵

Try it online!


Prolog, 48 42 bytes

Code:

p(X,Y,P,Q):-Y-2<Q,Q>=abs(X-P)+Q//7+Y//8*5.

Examples:

p(1,8,1,7).
true

p(3,4,3,2).
false

Not a bad challenge for Prolog compared to most.

Edit: Saved 6 bytes by switching to the formula used in grc's Python 2 answer.
Unfortunately Prolog can't chain comparisons as python can and integer division is 1 byte longer than float division.

Try it online here