Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Retrograde Analysis of Kriegspiel Endgames: Paolo Ciancarini and Gian Piero Favini

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

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

412 2010 IEEE Conference on Computational Intelligence and Games (CIG’10)


is impossible in this context. In the case of a game-ending
message such as ”checkmate” or ”draw”, ev returns the
same metaposition it received as an input if the message
is possible. If ”draw” is possible, then no other message is,
as explained above. The definition of ev is trickier than its
actual meaning: it works by erasing the black kings that are
incompatible with the message, and if the message is not
”illegal” it moves the black kings to any location a real black
king could visit from the current positions.
A metaposition m ∈ L is won if it satisfies either one of
these conditions:
• ∃x ∈ Sq , y ∈ M sg : ev(m, x, y) 6= ∅ ⇐⇒ y =
2

”checkmate”; that is, there is a certain checkmating


move (mate in 1);
• ∃x ∈ Sq
2
: ev(m, x, ”draw”) = ∅, ∀y ∈ M sg :
Fig. 2. If white plays Kc3, he can hear nothing (silent), ”rank” or ”illegal” ev(m, x, y) 6= ∅ ⇒ ev(m, x, y) is won; that is, there is
from the referee, respectively. a move that does not lead to a draw and whose possible
outcomes are all won.
move as an ordered pair of squares, that is, (s1 , s2 ) ∈ Sq 2 . This definition of victory excludes probabilistic wins
Chess rules provide us with a pseudolegal move function through mixed strategies: it only includes metapositions that
lglmv : L → P (Sq 2 ) that returns a set of moves that have are won against an omniscient adversary starting on his
a chance of being legal in the current metaposition. most favorable square and possessing foresight of our own
Making a move is formalized as follows. There is a strategy. At this point, one can define
set of messages M sg, which models the possible answers W = {m ∈ L : m is won},
from the referee in the particular Kriegspiel version being
played. In our case, under ICC rules, M sg = {legal, illegal, the set of all won metapositions. This set, while smaller than
checkmate, draw, rank, file, short diagonal, long diagonal, L, is ostensibly still very big; it suffices to consider that KQK
knight, double check}. The last six messages occur when is virtually always won because the queen cannot be actively
the move results in a check, and inform the players
6 about attacked by the black king. Our main interest, then, is a small
the direction of the offending piece from the black king’s subset of W : the set of largest metapositions with the same
point of view. optimal strategy. In order to define this, we need to define a
There is one difference between this referee and the one function dist : W → N returning the maximum distance to
used in an actual game: this one is a worst-case referee and mate for each won metaposition, expressed as the number of
will output a ”draw” message if there is the slightest chance actual white moves (not tries) required to win. We can now
of the game being a draw. This is equivalent to stating that define the new set
in the worst case Black can select the referee’s message just
7
like he would select his move 8
in chess. Under these premises, 9
B = {(d, S) ∈ W : ∃(d, S ∗ ) ∈ W, S ⊂ S ∗
the game turns into one of perfect information.
⇒ dist((d, S)) < dist((d, S ∗ ))}.
From a metaposition and a referee’s message it is easy to
generate a new metaposition that reflects the consequences This definition should be read as follows: a won meta-
of that message. Clearly, metapositions will not allow all position will be in B if any larger won metaposition (a
messages and a majority of them will only be compatible superset of it, with all its black kings and then some) requires
with a few. For example, only king moves can be illegal, more moves in order to achieve victory. In other words,
and only knight moves can give a knight check. Figure 2 metapositions in B are optimal in the number of moves to
shows a metaposition that allows three different outcomes checkmate; if any black king is added, the metaposition is
to the same move. It is to be noted that, while in the first either not won anymore, or it is won but it takes more moves
two there has been a black move following Kc3 (as seen, for to do so. If the metaposition is the largest possible one for
example, in the black kings spreading towards the top right its disposition, it is still included in B because the left-hand
corner), in the event of an illegal move black did not get an side evaluates to false.
opportunity to move. Of course, as long as it is still white’s Figure 3 illustrates L, W and B, showing an element from
turn and the metaposition is legal, our formalism is satisfied. each set. The first metaposition is legal, but clearly not won:
We can represent this through an evolution function all moves leave the rook in danger of being captured. The
second position can be won with Boyce’s algorithm, but it
ev : (L × Sq 2 × M sg) → (L ∪ {∅}),
is possible to win a larger one – the third – with the same
which accepts a legal metaposition, a move and a message, number of moves, and indeed with the same strategy. The
returning a legal metaposition or the empty set if the message reason is that the information about the black king not being

2010 IEEE Conference on Computational Intelligence and Games (CIG’10) 413


More specifically, it is our aim to build an algorithm that
exhaustively computes B given a set of white pieces. Also,
the algorithm will associate to every element b of B its
corresponding dist(b), as well the optimal move (or sequence
thereof, should the first be illegal) to try from there. This will
be our endgame database and it is enough to play any won
(a) (b) (c)
metaposition optimally, as shown in the following
Theorem. Let B be available for a given set of white pieces,
L W B and let dist(x) be known for all x ∈ B. Also, let all x ∈ B
have an optimal sequence of moves mx1 , . . . , mxn ∈ Sq 2
such that playing such a sequence will lower the distance to
mate by at least 1. Then, it is possible to:
• determine whether any legal position l ∈ L is won (l ∈

Fig. 3. L, W , B and a sample element from all three. W ?)


• if it is won, determine dist(l) and the optimal strategy

kZ0Z0Z0Z
j0Z0Z0Z0 kj0Z0Z0Z
jkZ0Z0Z0
leading to checkmate.

kZ0Z0Z0Z kj0Z0Z0Z Proof. We prove this theorem constructively, that is, we


j0Z0Z0Z0
kZ0Z0Z0Z jkZ0Z0Z0
kj0Z0Z0Z
provide a strategy for querying B like a database. This is a
very simple strategy that can be used in a real-world program
j0Z0Z0Z0
0Z0Z0Z0Z jkZ0Z0Z0
0Z0Z0Z0Z
such as Darkboard. In this context, playing ”optimally”

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),

414 2010 IEEE Conference on Computational Intelligence and Games (CIG’10)


then (d, S) meets all requirements for being in B, and kriegRetrograde(entryList,depth)
it should have been returned by the algorithm. Hence the begin
selected strategy is both valid and optimal. added = false;
The theorem above proves a very important point: that it for each disposition of white pieces P
is possible to play all won metapositions optimally while do
only knowing a small subset B ⊂⊂ W . The next sections for each pseudolegal move M do
describe the actual retrograde analysis algorithm that builds messages = possibleMessages(P,M);
B and computes the data stored with its elements. for each assignment A of entries from
entryList to messages do
IV. A PERFECT PLAY ALGORITHM if (generateAndAdd(entryList,P,A))
We need to construct B iteratively. If Bx ⊆ B = {b ∈ added = true;
B : dist(b) ≤ x} represents the subset of metapositions in od
B that can be won in at most x moves, it is clear that, by od
increasing x, at some point ∃k ∈ N : Bx = B ∀x ≥ k, od
because B is not infinite. Thus, a simple inductive reasoning if (added)
shows that what is really needed to construct B is: kriegRetrograde(entryList,depth);
• an algorithm for building B1 ;
else if (entriesWithDepth(depth+1))
• an algorithm for constructing Bx+1 from Bx .
kriegRetrograde(entryList,depth+1);
return entryList;
Intuitively, B1 is not hard to construct: it suffices to try
end
every move for each disposition of white pieces, and see
which locations of the black king would be a mate in 1 on Fig. 5. Pseudocode listing for main retrograde function.
a regular chessboard. Figure 1, (c) shows one of the only
examples of single-move checkmates in KRK with more
than one king location. The latter algorithm is obviously
metaposition in entryList will be tested for each referee’s
much more challenging. The simplest way to think of the
messages, and the same metaposition can appear more than
solution is: if, given a metaposition and a move, we can
once in the same assignment set for different messages –
establish that all outcomes of that move are either in Bx
even all of them. After all, the meaning of the assignment set
or subsets of elements in Bx , then we know that such a
is ”if message x happens, the problem reduces to previously
metaposition can be won in at most x + 1 moves. The actual
solved metaposition y”, so it is perfectly possible for a single
problem is making the metaposition maximal, that is, finding
metaposition to cover several messages.
a metaposition such that none of its supersets can be won in
x + 1 moves. Still relying on intuition, rather than building The method generateAndAdd creates a metaposition
random metapositions and testing them against the elements from the assignment set and checks if it is a subset of
in Bx , the solution will be constructed from the elements in something already in B. If it is new, it adds it to entryList
Bx themselves. and returns true. If all assignments are tested without any
The key observation to be made here is that given a additions to the database, this depth level is considered
metaposition b ∈ B, a move v ∈ Sq 2 and an assignment exhausted, with entryList now representing Bx+1 : the
set associating metapositions to referee’s messages as in algorithm now starts over at the next depth, but if there are no
A = {(b1 , m1 ), . . . , (bn , mn )}, bk ∈ B, mk ∈ M sg, m suitable metapositions of the right depth, that is Bx = Bx+1
distinct, it is possible to construct b∗ ∈ L : ∀(bx , mx ) ∈ it terminates execution, having found B in its entirety. On
A ev(b, v, mx ) ⊆ bx ; that is, b∗ is a legal metaposition whose the other hand, if it found new metapositions, it starts a new
outcomes will be contained in the metaposition associated iteration at the same depth; this is necessary because of illegal
with each message. Moreover, if the assignment is exhaus- moves. Metapositions of depth x + 1 found during the first
tive, b∗ ∈ W ; the metaposition is won because there is a iteration can create more metapositions of the same depth in
move whose outcomes are all won. If one tries all possible the second iteration by being associated to the illegal message
assignments, sooner or later the maximal elements belonging in the assignment set, and so on. In most cases, it takes 3-5
to B will be generated. The method for doing this operation iterations to completely clear a depth level; these correspond
is lengthy, but rather trivial. The problem merely becomes to the 2-4 illegal moves the white king might make, at most,
one of exploring millions of assignments and storing the best before a legal move is found.
ones. This algorithm requires exponential time in the number
Figure 5 describes a skeletal version of the algorithm. It of pieces and possible referee’s messages; KQK takes the
accepts two parameters as its input: entryList, which longest time to compute because the queen can check in four
is basically Bx , and the depth level x + 1. What it does different directions. The space required by the algorithm only
is create all possible dispositions of white pieces, and for depends exponentially on the amount of white pieces, not the
each of those all pseudolegal moves are considered. All messages. The size of B is bounded by the size of L, which
compatible assignments are tried: this means that the same can be estimated as shown in the previous section.

2010 IEEE Conference on Computational Intelligence and Games (CIG’10) 415


A. The lookup algorithm 1000000
KRK
KQK
900000 KBBK

Once the algorithm has finished, it returns a full list of KBNK

metapositions, each having a best move and a distance to


800000

mate in the worst case. The database goes through a series 700000

of post-processing steps and is finally stored as a text file 600000

in which every line represents a single entry. A sample line 500000

from the KRK database reads as follows: 400000

300000

kkkkkk2/7R/kkk5/8/4k3/2K1k3/4k3/3k4 26
200000
Kc3-d3 Kc3-d4 Rh7-h5
100000

The metaposition itself is represented through standard FEN 0

(Forsythe-Edwards Notation), with multiple black kings on 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86

the board. This board representation is followed by the


maximum distance to mate and the sequence of moves that Fig. 6. Metaposition distributions by distance to mate in the four databases.
the white player should try from here, starting from the first
and moving to the next should it be illegal.
This database is used as indicated in the proof to the Theo- messages or another depth 10 entry linked to the illegal
rem. The player searches it with a metaposition representing move message. Any assignment violating this rule is
the current state of the game. All entries that are supersets skipped.
of it are returned, and if none exist, it means that it is not • Not every single metaposition in the list is checked. In
possible to force a mate from here. Among these entries, particular, at the end of each step, metapositions that
the player selects the one with the shortest distance to mate; are found to be subsets of others are “dumped” into
in the event of a tie, he will pick the one with the lowest support files, regardless of their distances to victory;
number of states (black kings). He will then proceed to play the only exception is metapositions generated during
the corresponding move, which is optimal. the last step. This is related to the above point; when
determining depth 10 entries, there will always be at
B. Complexity and optimizations least one depth 9 or depth 10 metaposition in the
The computational complexity of a single depth step of assignment, but as for the others it is irrelevant whether
the algorithm is O(bp nm ), where b is board size, p is the their depth is 8 or 2. One can simply take the larger
number of white pieces on the board, n is the average size one and dump the smaller. As a consequence, the final
of the metaposition list, and m is the number of messages database is obtained by merging all the dump files with
the referee can output. Estimating n is best done through the collection that remains after the last iteration of the
the actual experiment, which shows that its increase is algorithm.
exponential and quite regular at first and until about two • A further optimization to reduce the number of meta-
thirds of the entire run, after which there is a sharp slowdown. positions being considered is to perform an intersection
This algorithm can become very slow if there are many between each entry and the legal positions of the black
possible referee messages. This is why KQK took the longest king after the corresponding message. In this way, only
time out of all test scenarios: the same move can often the relevant parts of the metaposition are considered,
generate up to five messages, four of which are checks. and duplicates can be computed only once.
The following optimizations are possible and have been
implemented. V. T EST CASES
• Game-ending referee messages are handled implicitly. The database-building algorithm was implemented in Java,
Black king positions leading to instant checkmate are modified for parallelization and run on an eight-core ma-
automatically added to any new entry, and stalemate chine. Parallelization was handled by splitting the metaposi-
or drawn positions are excluded before anything else tion list and having each thread focus on the predecessors of
takes place. This means that two referee messages can its own subset; since the algorithm needs read-only access
be taken off the list, leaving only three in KRK - silent, to most shared data, the task was not overly challenging.
illegal and check. Four scenarios have been executed so far: KRK, KQK,
• Not every metaposition assignment is considered, but KBBK and KBNK. Execution time ranged from about six
only those that will create a metaposition of the desired hours for KRK to seven days for KQK, with KBBK taking
depth. For example, if we are filling the database with about three days and KBNK taking five. The dimensions
depth 10 entries, it is useless to try an assigment leading of the resulting databases are radically different, as seen
to depth 9 or less, because it will already have been in Figure 6. The figure shows distributions by distance to
considered at the appropriate step. In other words, in mate, and provides visual information as to how large a
order to generate a depth 10 entry, we need to have at database is; moreover, checkmates for the general positions
least one depth 9 entry assigned to the silent or check usually encountered in practical gameplay (that is, positions

416 2010 IEEE Conference on Computational Intelligence and Games (CIG’10)


1600000
KRK
of initial configurations and no information on the black
king. Using mirroring on the x, y and diagonal axes, the
KQK
KBBK
1400000
KBNK

problem of KRK in Kriegspiel is described with a database of


1200000

635,968 metapositions. KRK in chess is fully described with


1000000
about 23,000 positions, making the equivalent Kriegspiel
800000
problem about 30 times as complex. Results may vary to a
degree, depending on optimizations and storage policies for
metapositions that are subsets of other entries; for instance, in
600000

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

2010 IEEE Conference on Computational Intelligence and Games (CIG’10) 417


TABLE I
COMPARISON BETWEEN FERGUSON’S ANALYSIS AD OUR the original diagram identifiers; use of < X denotes a
FINDINGS FOR KBBK probabilistic mixed strategy with an estimated upper bound.
Position Ferguson database Interestingly, the difference between estimated upper bounds
k6B/k1K5/8/8/2B5/8/8/8 4 (Kb6) 4 (Kb6) and actual distance to mate according to the database does
k7/k1K5/3B4/8/2B5/8/8/8 5 (Be7) 5 (Be7)
k1B5/k7/8/1K2B3/8/8/8/8 7 (Kc6) 7 (Kc6) not grow uniformly with the length of the problem. Some of
kk6/1k1K4/8/8/2BB4/8/8/8 9 (Kc6) 9 (Kc6) the largest gaps are found in medium depth entries, whereas
8/8/k1B5/k1B5/2K5/8/8/8 12 (Bd4) 11 (Kd5) there are smaller discrepancies in some later metapositions.
kkkkk3/8/2K5/2B5/2B5/8/8/8 16 (Be6) 14 (Kd7)
8/8/k7/kk1B4/kk1B4/k2K4/8/8 18 (Kc3) 14 (Kc3) Probabilistic strategies that differ less from the database
8/k7/kk1B4/kk1B4/k2K4/8/8/8 14 (Kc4) 13 (Kc4) findings are more effective than the others and considerably
kkkk4/1kkk1K2/2kk4/8/2BB4/8/8/8 20 (Ke7) 16 (Ke7) simplify the game.
kk6/kk1K4/kk6/1kk5/8/1BB5/8/1kk5 20 (Kc6) 15 (Kc6)
VI. C ONCLUSIONS AND FUTURE WORK
TABLE II Our algorithm has solved four Kriegspiel endgames with a
COMPARISON BETWEEN FERGUSON’S KBNK ANALYSIS AD OUR reduced number of pieces but of considerable complexity; in
FINDINGS FOR KBNK
particular, prior to this work it was not even known whether
Pos F Tb Pos F Tb Pos F Tb
2A 5 5 4A < 26 21 5C < 62 47
a pure strategy existed for winning KBNK in a fixed number
2B 7 7 4B 24 18 5D < 60 45 of moves. A similar approach can be applied to any imperfect
3A 15 14 4C 14 14 5E < 56 45 information game in which one side can win with probability
3B 13 13 4D 10 10 5F < 52 42
3C 8 8 4E < 42 36 6A < 86 77
1 but the strategy for doing so (especially optimally) is too
3E 15 13 4F < 36 33 6B < 72 51 complex to calculate at runtime.
3F 12 11 4G < 31 28 6C < 81 75 The databases are all available on line or on request from
3I 15 10 4H < 29 26 6D < 80 75
3J 24 23 5A < 72 52 7A < 95 79
the authors. Larger endgames have yet to be computed,
3K 19 18 5B < 70 52 7B < 91 78 mostly because of resource constraints. Other interesting
Kriegspiel endgames to be investigated include KRRK,
KQRK, KQQK and KNNNK. Indexing and compression
seem to be the next main problem to be faced in order to
more when it comes to reacting to illegal moves), but sub- solve these other endgames. Currently, there is no indexing
optimal behavior in a small number of situations seems to be to the database, forcing the algorithm to look up a large
enough to slow down checkmate by as much as 33%. The number of entries in response to a query. Also, database are
positions considered by Ferguson to be impossible to win quite large, with only a tiny fraction of their entries being
with certainty are indeed not found in the database, though actually useful in a real game. This leads to the problem
the database contains many slightly more restrictive entries of compressing a database by removing positions that are
that can always be won. These positions actually form the unlikely to occur, at the risk of selecting a sub-optimal
bulk of its nearly eight million entries. strategy if those positions actually occur. A separate problem
is that of expanding the databases to find positions that are
D. KBNK
won with probability arbitrarily close to 1 through recursive
KBNK is the most complex among the four endgames we mixed strategies.
examined with retrograde analysis. At 17,508,207 entries,
it is also the largest database as well as the one with the R EFERENCES
longest distances to mate: up to 89. Depending on the starting [1] Nalimov, E., Haworth, G., Heinz, E.: Space-efficient indexing of chess
position, most scenarios can be won in 70-80 moves in the endgame tables. ICGA Journal 23(3) (2000) 148–162
[2] Ferguson, T.: Mate with bishop and knight in Kriegspiel. Theoretical
worst case. In order to win a position in this scenario, it may Computer Science 96 (1992) 389–403
be necessary to disable the 50 move rule. [3] Ciancarini, P., DallaLibera, F., Maran, F.: Decision making under
This is the only instance of three different pieces collabo- uncertainty: a rational approach to Kriegspiel. In van den Herik, J.,
Uiterwijk, J., eds.: Advances in Computer Chess 8, Univ. of Rulimburg
rating towards checkmate. Moveover, it is the only endgame (1997) 277–298
for which, prior to the present research, it was unknown [4] Ferguson, T.: Mate with two bishops in Kriegspiel. Technical report,
whether it could be won with a pure strategy in a fixed UCLA (1995)
[5] Boyce, J.: A Kriegspiel endgame. In Klarner, D., ed.: The Mathematical
number of moves. Ferguson studied this endgame in [2] Gardner. Prindle, Weber & Smith (1981) 28–36
and concluded that it could be won 100% of the time [6] Bolognesi, A., Ciancarini, P.: Searching over metapositions in
starting from stable positions, but believed that doing so Kriegspiel. In van den Herik, J., Björnsson, Y., Netanyahu, N., eds.:
Computer and Games 04. Volume 3846 of Lecture Notes in Computer
required some sort of randomized strategy at several key Science., Ramat-Gan, Israel, Springer (2004) 246–261
points throughout the algorithm. [7] Sakuta, M., Iida, H.: Solving Kriegspiel-like Problems: Exploiting a
Even one sub-optimal line of play can raise distances to Transposition Table. ICCA Journal 23(4) (2000) 218–229
[8] Ciancarini, P., Favini, G.: Solving Kriegspiel endings with brute force:
mate considerably. The effect in KBNK is more evident the case of KR vs. K. In van den Herik, J., Spronck, P., eds.: Proc.
than in KBBK because of the greater complexity of this 12th Int. Conf. on Advances in Computer Games (ACG). Volume 6048
endgame. A full comparison between the results in [2] and of LNCS., Pamplona, Spain, Springer (2009) 136–145
database computations is given in Table II. The table uses

418 2010 IEEE Conference on Computational Intelligence and Games (CIG’10)

You might also like