# How to mathematically determine if king and pawn versus king endgame is a draw or a win?

I am aware of questions such as this one which discussed a method of determining if a king pawn vs king endgame is a draw or not. The accepted answer gave detailed guidelines but is not mathematically strict. I am asking the question again, but from a different angle.

If we label all the squares of the board as 1, 2, ..., 64 and we will use three numbers to denote the position of white king, black king, and white pawn, respectively. Let f be a function whose domain is a subset of {1,...,64}×{1,...,64}×{9,...,56}×{0,1} and whose range is {1/2,1}. Here × denotes the Cartesian product and the third set is {9,...,56} instead of {1,...,64} as it denotes the position of the white pawn. The fourth set {0,1} denotes whose turn it is; 0 for white and 1 for black. For the range, 1/2 means draw and 1 means win for white (assuming both sides only play the best moves possible). The actually domain is a subset of {1,...,64}×{1,...,64}×{9,...,56}×{0,1} instead of the entire set since no two or more pieces can occupy the same square and two kings cannot be adjacent to each other.

With the above definition, f is a function whose domain contains fewer than 64×64×48×2=393216 elements and whose range contains 2 elements. So it is possible (though may be difficult) to express f explicitly.

My question is: How to mathematically determine the output of the function f, given any input and therefore determine if a king and pawn vs king endgame is a draw or not?

In other words, I am looking for a way to find the value of f(x,y,z,w), where x denotes the position of the white king, y for the black king, z for the white pawn, w for whose turn it is and the output of f can only be 1/2 and 1.

• Many chess engines implement such a function in their evaluation, but as a precomputed bitbase (only a few KB, even less after exploiting board symmetries) rather than doing so mathematically. Jul 21, 2019 at 9:22

You can do this (the space is, after all, finite) but it ends up being tedious, and is probably inferior to just looking it up in a tablebase.

Let's start with one of the most basic concepts in king and pawn endgames: the pawn square. White generally wins if Black is too far away to enter the square. We just need to convert this rule into simpler rules, and then convert those into your mathematical scheme.

If, with White to move, the White pawn is farther advanced than the Black king, White wins. If, with Black to move, the White pawn is 2 ranks farther advanced than the Black king, White wins.
So, if `floor(y/8) + w < floor(z/8)` then `f(x,y,z,w} = 1`.

If, with White to move, there are more files between the Black king and the pawn than there are ranks between the White pawn and the 8th rank, White wins. If, with Black to move, there are 2 more files between the Black king and the pawn than there are ranks between the White pawn and the 8th rank, White wins.
So, if `abs((y mod 8)-(z mod 8)) + w < (8-floor(z/8))` then `f(x,y,z,w} = 1`.

But we aren't done yet. If the pawn is on the second rank, it can go an extra square on its first move. But if Black has the move and is next to the pawn, he might be able to capture the pawn right away before it can move those 2 squares.
So, if `z` is in {9...16}, and `w = 0` or `(abs(z/8 - y/8 > 1)` or `abs((z mod 8) - (y mod 8) > 1)`, then if `((y mod 8)-(z mod 8)) + w+1 < (8-floor(z/8))` or `floor(y/8)+w+1 < floor(z/8)` then `f(x,y,z,w} = 1`.

But we still aren't done. There's an exception to the pawn square rule. Here, Black is outside the square and cannot enter it, but the game is drawn because of stalemate:

``````[FEN "K7/P7/3k4/8/8/8/8/8 b - - 0 1"]

1... Kc7
``````

So now, to be complete, we'd have to exclude the situation where the White king is in the corner, blocking his own pawn, and Black can trap him in that corner. This function is getting very convoluted already, and that's just one of the most basic concepts.

• This is a great answer!! Thank you so much for your time and effort! Jul 21, 2019 at 11:26

Case 1: Both kings are away from the passed pawn: IF Black can get into the square, it is a draw.

Case 2: The Black King is in front of the pawn: depends on the position of the White King

Case 3: Black's king is outside the square, but White has a rook-pawn - If Black's king is in front of the pawn, it is a stalemate, and in some other cases, White's king may be trapped in a corner and stalemated.