Retrograde Analysis of Kriegspiel Endgames: Paolo Ciancarini and Gian Piero Favini
Retrograde Analysis of Kriegspiel Endgames: Paolo Ciancarini and Gian Piero Favini
Retrograde Analysis of Kriegspiel Endgames: Paolo Ciancarini and Gian Piero Favini
Abstract—A game tree can be constructed starting from its several endings, including King and Rook vs King (KRK),
leaves with a technique called Retrograde Analysis. It is useful King and Queen vs King (KQK), King and two Bishops vs
to solve some specific subsets of a game like chess, in order King (KBBK), and King and Bishop and kNight vs King
to achieve optimal play in endgame situations. Position values
can then be stored in databases for instant access, in order (KBNK). In the latter case we improve and correct some
to obtain perfect play at no time cost. This paper shows that results included in a paper published on this topic [2].
such an approach can be used to solve subsets of Kriegspiel, This paper is structured as follows. In section II, we
an imperfect information game. Using a brute force retrograde describe Kriegspiel and summarize previous research in
analysis algorithm, a suitable data representation and a special the field. Section III describes the problems in retrograde
lookup algorithm, we achieved perfect play, perfection meaning
fastest checkmate in the worst case and without making any analysis of imperfect information games. Section IV con-
assumptions on the opponent’s strategy. We investigate some tains the actual algorithm, as well as considerations on
classic Kriegspiel endgames. We have built databases for each its correctness, complexity and optimizations. Section V
of these endgames and cast light on some long standing open contains information and experimental results for each tested
problems. endgames. Finally, conclusions and future perspectives are
I. I NTRODUCTION given in Section VI.
It is possible to explore significant subsets of a game tree II. K RIEGSPIEL
in such a way that, if a particular position is encountered Kriegspiel is played on three chessboards in different
during gameplay, its value has already been computed and rooms, one for each player and one for the referee. From
the best strategy is immediately available. Most programs the referee’s point of view, a game of Kriegspiel is a game
for playing chess include a so-called “endgame database”, of chess. The players, however, can only see their own pieces
because the perfection of database-powered play is unap- and communicate their move tries to the referee, so that
proachable by any evaluation function, and in some cases by there is no direct communication between them. If a move is
the strongest human player. databases are usually obtained illegal, the referee will ask the player to choose a different
through retrograde analysis: a game tree is visited starting one. If it is legal, the referee will instead inform both players
from terminal nodes, namely the leaves in the game tree as to the consequences of that move, for instance whenever a
corresponding to checkmates and stalemates, and then the check or capture happens, when a move is illegal, and when
analysis moves backwards in time to find out predecessors to the game ends. Kriegspiel is not a standardized game, as
those positions, until all possible layouts of the desired type there are several known sub-variants to the game; they differ
have been explored. The concept has been widely studied in how much information the referee shares with the players
since the ’60s, so there is a large bibliography devoted with respect to pawn moves and captured pieces. Since our
to databases and their creation, especially for chess and main concern in this paper is with pawn-less endgames, the
checkers. For instance, the so-called Nalimov tables [1] today choice of ruleset is irrelevant.
are the de facto standard for serious chess programs. Several endings have been studied, though so far always
The aim of this paper is to show that the same concept can with the aid of heuristics or game-theoretic considerations.
be successfully applied to a game of imperfect information, For example, [3] deals with King and Pawn vs. King (KPK)
as well. Specifically, it can be applied to games which can using a set of directives and distinguishes between algo-
be somehow transformed into perfect information games in a rithmically won endings, which can always be won, and
meaningful way. Unlike other game-theoretical methods, this statistically won ones, wherein victory is only achieved with
is only limited to finding positions where a player can force probability 1−, with small (arbitrarily small in the absence
victory with probability 1, but these positions, once found, of the 50 move rule). It is shown that certain instances
can be played optimally. We use Kriegspiel (invisible chess) of the KPK ending are of the former type, and some are
as an example. The game is identical to chess, i.e. it has the of the latter. Ferguson studied two less common and more
same pieces and rules, except players can only see their own difficult endgames, namely KBNK in [2] and KBBK in [4].
pieces and need to rely on messages from a referee to figure He concluded that these can also be won algorithmically,
out where the opponent is. provided White can set up his pieces in particular patterns
We give an algorithm for solving Kriegspiel endings that and the black king is confined to certain areas of the board.
have so far only been approached with approximated or KRK is the most widely studied ending, probably because
heuristic methods, and use it to build Kriegspiel databases for it is so simple in Chess but not so simple in Kriegspiel, even
P. Ciancarini and GP. Favini are with the Dept. of Computer Science, though it is always won if White can secure his rook. [5]
University of Bologna, Italy. studied an algorithm for solving Kriegspiel KRK, expressed
978-1-4244-6297-1/10/$26.00
2010
c IEEE 411
Let us begin by defining the sets and functions on which
we are operating. Let Sq = {a1, . . . , h8} be the set of
squares on the chessboard. A disposition is a way of arrang-
ing the existing, visible white pieces, and we can represent
it as unordered piece sequences of the form [Ka1, Rb1],
meaning the white king in a1 and a white rook in b1. The
(a) (b) (c) disposition set D is then the set of all possible dispositions
for a given piece set. Calculating the cardinality of D is
a simple combinatorial exercise; for example, |DKRK | =
Fig. 1. (a) Highest uncertainty in KRK; (b) useless information: after two
plies this board will be identical to the outcome of the same plies on (a); 64 × 63 = 4032. For the purpose of our algorithm, however,
(c) mate in one. we can make use of mirroring just like we would in chess.
4
All dispositions can be obtained by mirroring another along
the x or y axes, the right diagonal, or combination thereof.
as a series of directives in natural language and without any Obviously, this would not hold true in endings with pawns,
formalization. His algorithm focuses on reaching states in but for the purpose of our scenarios this will always be the
which both kings are in the same quadrant from the rook’s case. Mirroring reduces the cardinality of D by a large factor;
point of view, and then reducing the quadrant’s size. [6] used with only ten king positions to keep track of, we can define
metapositions, ad hoc evaluation functions, and minimax- a mirrored disposition set Dm that contains fewer redundant
like tree search to solve KRK in the general case, showing it dispositions. In this way, |DKRKm
| = 10 × 63 = 630. There
to perform better than Boyce’s directives. However, success is still some redundancy: dispositions in which the king lies
with this method cannot be guaranteed without trying out on the main diagonal could be halved in size by checking
every single case. the positions of the other pieces. However, we will be using
this incomplete mirroring scheme for the sake of simplicity
III. R ETROANALYSIS UNDER IMPERFECT INFORMATION and not make use of rotational symmetry.
It is easy now to define a metaposition in this context as
Retrograde analysis works for perfect information games.
a pair (d, S), d ∈ D, S ⊆ Sq. The rules of chess define a
Intuitively, for it to work in an imperfect information sce-
legality function lgl : D → P (Sq) that accepts a disposition
nario, we reduce it to the perfect information case. We
as its input and returns a set of legal squares (a subset of Sq).
abstract the black king’s moves so that multiple “virtual”
This function represents the legal locations for the black king,
black kings may exist on the board at the same time. What
assuming it is white’s turn. This is an assumption that we
we get is the merging of several hypothetical states which
are going to make throughout the paper - all diagrams show
evolve depending on possible observations, that is, referee’s
situations in which the white player is to move. This means
messages. While the actual message we hear upon trying a
the black king cannot be in check as we start. This allows
move is usually unpredictable, the possible locations of the
us to define the set of legal metapositions
black king following that message are entirely computable.
At this point, it suffices to imagine that the black player L = {(d, S) : d ∈ D, S ⊆ lgl(d), S 6= ∅} .
decides which message is returned by the referee among
the legal ones, and the whole game becomes one of perfect The legality function defines the maximum number of
information, albeit one played with different states than locations for the black king at any given time. That, of
chess. If we can always mate even with Black deciding the course, depends on the particular disposition: the minimum
outcome of our moves (i.e. we can beat an omniscient oracle) and maximum sets returned by lgl in the KRK ending are
then there exists a pure winning strategy that can be stored in 40 and 52, respectively. These two numbers alone provide a
a database. The maximum number of moves it takes to mate rough estimate of the cardinality of L. Since S can be any
is also fixed and corresponding to the oracle’s best defense. subset of lgl(d), which ranges between a given x1 and x2 ,
Throughout our analysis, we always suppose that the black we have that (2x1 −1)|D| ≤ |L| ≤ (2x2 −1)|D|. Again, using
king not to have any allies on the board. The aim of this KRK as an example and only counting the mirror dispositions
section is to prove that we can create an algorithm for playing in DKRK
m
, we can place the cardinality of L between 7·1014
Kriegspiel endings optimally through a database. We will and 3·10 ; more accurate estimates would place it at around
18
be working with diagrams containing actual white chessmen 1017 . It is certainly a huge number, especially next to the
and ”virtual” black kings representing possible game states. 24324 positions required to solve KRK in chess, but as we
These diagrams have been called in various ways by different will see this number is not all that significant.
authors. The term ’metaposition’ is probably best, as these We need two special subsets of L, one representing meta-
are not actual Kriegspiel (or chess) positions but simply positions that we can always win, and then a smaller set B of
mental models of possible positions [7]. However, we will ”best”, maximal metapositions that are our true objective and
occasionally refer to these diagrams simply as ’positions’ or the only ones required to play the whole endgame optimally.
’situations’ for brevity, when the distinction is obvious from In order to represent these two, we need to formalize the
its context. white player’s moves and the referee’s role. We can define a
kZ0Z0Z0Z
j0Z0Z0Z0 kj0Z0Z0Z
jkZ0Z0Z0
leading to checkmate.
J0S0Z0Z0 J0S0Z0Z0 means that at any given time we can checkmate in dist(x)
moves at most, even against an omniscient opponent. We
(a) (b) do not make any assumptions on the nature or play patterns
of the enemy; we simply consider worst-case performance,
Fig. 4. (a) is a mate in 9, play Rb1; (b) is a mate in 13, play Kb2, or if
illegal Kb1; however, (b)’s strategy can solve (a) as well.
much like a chess database.
Suppose we need to solve a legal metaposition l =
10 (d, S) ∈ L. The querying algorithm is as follows:
• Look for all (d, S ) ∈ B such that S ⊆ S . If none
∗ ∗
on the eight rank is useless: the only move that might get
a different outcome because of it is Ra8, which is unsafe exist, meaning that the metaposition has no supersets in
and must be discarded. All other moves generate the same B, then l is not won.
• On the other hand, if it is won, select the (d, S ) with
∗
metapositions in the two cases, so the smaller one can be
sacrificed without loss. Thankfully, most elements of W are the shortest distance to mate. Play the corresponding
like this, and we are entitled to hope that B may contain sequence of moves.
a small, computationally feasible fraction of the total. It is We need to prove that both steps are correct. The first step
readily seen from this example that there are 27 = 128 requires us to prove that (d, S) ∈ W ⇐⇒ ∃(d, S ∗ ) ∈
elements of W that are like the second metaposition but with B, S ⊆ S ∗ .
any combination of black kings on the eight rank, and hence • ⇒: obvious by construction. If a metaposition is won,
are not in in B. A deeper investigation would reveal that we it either is in B or its superset is.
• ⇐: B ⊆ W , so (d, S ) is won. Any subset of a won
∗
can take away even more squares with no consequences after
the first move, thus excluding tens of thousands of elements metaposition is also won – one can simply pretend not to
from B. know the additional information. A strategy that solves
At this point, one might wonder about the usefulness of (d, S ∗ ) also solves (d, S), hence (d, S) is won.
B and the reason for its definition. Why not just define it The second step requires us to prove that the selected strategy
as the set of all won positions that are not a strict subset is valid and optimal. Obviously, the strategy is valid because
of any other won position? The reason is a practical one, of the same argument as before: a strategy that solves a
and it is best demonstrated with an example. Figure 4 shows metaposition also solves any of its subsets. This does not
two metapositions, with (a) being a subset of (b), but both guarantee that it will do so optimally, however: as seen in
their distances to mate and correct strategies are different. In Figure 4, one can solve (a) with (b)’s strategy, but doing
(a), keeping the king confined to just one file is the optimal so requires 13 moves instead of the optimal 9. On the
strategy, which is obviously not possible in (b). If B is to other hand, suppose that the selected strategy is indeed sub-
capture all ”important” metapositions, it obviously has to optimal, that is, dist(d, S) < dist(d, S ∗ ). But this means
contain both (a) and (b). If both could be solved in the same (d, S) should have been an element of B, as well: by
amount of moves, one could simply use (b)’s strategy for (a), construction, B = {(d, S) ∈ W : ∃(d, S ∗ ) ∈ W, S ⊂
as well – the additional information in (a) would be ignored S ∗ ⇒ dist((d, S)) < dist((d, S ∗ ))}. Since dist(d, S ∗ ) >
at no cost, and we would not need to have (a) in B. dist(d, S) is the minimum distance for a superset of (d, S),
mate in the worst case. The database goes through a series 700000
300000
kkkkkk2/7R/kkk5/8/4k3/2K1k3/4k3/3k4 26
200000
Kc3-d3 Kc3-d4 Rh7-h5
100000
400000
our database boards with the white king on the main diagonal
200000
are not further mirrored with the position of the rook. There
are 2207 entries with only one black king on the board.
0
1 6 11 16 21 26 31 36 41 46 51 These metapositions look exactly like chess positions, and
their presence is roughly equivalent to saying that roughly
10% of the time there is a specific, optimized strategy for
Fig. 7. Metaposition distributions by number of black kings on the board.
checkmating the black king that can only be applied if its
initial position is known with certainty. The remaining 90%
are subsumed inside larger metapositions with two or more
in which White knows nothing about the black king) are
kings.
mostly located near the distribution’s peak. Entries to the
The longest forced mate sequences in Kriegspiel KRK are
right of the peak are riddle-like and require the white player
37 moves long, making the 50-move rule irrelevant in this
to spend moves protecting his pieces and reaching a stable
endgame. There are 50 entries for this depth in the database.
configuration. It should be noted that KBNK is unique among
See [8] for a presentation of our results on this ending.
the four in its irregular development. In particular, very
few entries exist before depth 35, after which the database B. KQK
explodes. The fact it takes so long to find general strategies The king and queen vs. king endgame is the fastest to
for KBNK is probably the main reason why a general pure win, yet one of the slowest to compute because of the larger
strategy for this endgame was never found through manual number of referee’s messages that most moves can generate.
analysis. At 2,150,833 entries, it is over three times as large as KRK,
Figure 7 represents distributions by the amount of black and can be won roughly twice as fast with similar strategies
kings on each entry. If the database contained every possible and comparatively fewer illegal moves. The longest forced
legal metaposition, the resulting graph would resemble a mate in KQK takes 18 moves in the worst case; there are 33
Gaussian, being the sum of binomial distributions with such instances in the database.
similar coefficients (each king either is or is not present on
the board). The actual databases all show a skew towards C. KBBK
entries with fewer kings; the longer the endgame, the larger The KBBK database contains 7,887,296 entries, with the
the skew. This fact does not immediately prove anything longest forced mate spanning 43 moves; there are only 5 en-
about the database’s compression power, that is, the ratio of tries at this depth. We remark that the database only contains
database entries compared to all won metapositions. In this positions with the two bishops standing on differently colored
sense, KQK is the easiest case to compute since almost every squares. This endgame, together with KBNK, is particularly
game can be won with probability 1, the queen being safe interesting because there is existing research to compare the
even when the white king is far away. The KQK database database with. In fact, KBBK has been studied by Ferguson
is slightly over two million entries, with about 1016 possible in [4], which correctly points out that it cannot be won for
metapositions. This means that the database contains two in every starting position, even if the white pieces are initially
1010 elements, having a compression power of approximately safe. This is because the two bishops cannot directly protect
99.99999998%. The other endgames are less straightforward, each other; they can only stand side by side and block the
since they all contain entire classes of situations that cannot enemy king from the front and back, but not the flanks.
be won with absolute certainty. If the king starts out separated When the white king moves to clear one quadrant, it leaves
from the other white pieces, victory will not be guaranteed a bishop unguarded, therefore the game cannot be won with
in a majority of cases. For KRK, it can be argued that probability 1. However, if the pieces start out close enough
compression ratio is even higher than KQK, because it is less to the edge of the board, the king needs only protect one
than one third the size and roughly half legal metapositions flank, and victory is guaranteed.
can be won (if the rook starts on the same or adjacent rank Table I shows a comparison of Ferguson’s analysis and
or file to its king, the game is almost always won). our KBBK database. It can be seen that, for simpler mates,
results and strategies are more or less identical, but manual
A. KRK analysis starts to fall behind retrograde analysis as positions
KRK is arguably the simplest Kriegspiel endgame in become larger and more complicated. Interestingly, strategies
which victory can always be obtained from a sizeable amount do not differ in a majority of cases (though they differ