lichess-org / lila-tablebase

Tablebase server

Home Page:https://tablebase.lichess.ovh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consistency between /standard and /standard/mainline endpoints

pkacprzak opened this issue · comments

I'm using the API for the Reddit bot and people just reported it provided a wrong continuation line so I'm trying to examine it further.

Here is the FEN: 7k/8/1R6/R7/8/8/8/4K3 w - - 0 1

Now, http://tablebase.lichess.ovh/standard?fen=7k/8/1R6/R7/8/8/8/4K3_w_-_-_0_1 says that the best move is Ra7 and indeed it is, but mainline returned by http://tablebase.lichess.ovh/standard/mainline?fen=7k/8/1R6/R7/8/8/8/4K3_w_-_-_0_1 starts with Rg5 which is obviously not the best move (still a win but not the quickest one).

I'm basing the bot's internal logic on the assumption that if the /standard endpoint returns dtm different than null then /standard/mainline returns mainline leading to mate with the given dtm. Now I'm wondering if this assumption is even valid?

Syzygy tablebases guarantee winning won positions, but not the shortest path to mate (only the shortest path to the next winning pawn move or capture). To quote https://syzygy-tables.info/:

DTZ optimal play is not always the shortest way to mate (DTM) and can even look unintuitive: For example sometimes pieces can be sacrificed to reset the fifty-move counter as soon as possible. However, unlike DTM it achieves the best possible result even with the fifty-move rule.

Now back to this API.

/standard/mainline provides the pure DTZ mainline. Checkmating on the next move is valued no differently than making a pawn move and checkmating later.

/standard move ordering takes some auxiliary information into account:

https://github.com/niklasf/lila-tablebase/blob/c996c1b6c243ab64a301201eeabfe89d0121d76b/src/main.rs#L344-L352

In particular it orders also by DTM values obtained from 5-piece Gaviota tablebases, if Syzygy tables say that the 50-move rule is not relevant.

So the endpoints are different in that regard, the latter closer to what you're looking for, and I believe neither exactly it.

Thanks for the explanation. I knew about the DTZ approach but didn't know what exactly the /standard/mainline returns, now it's clear. I think I'd just follow your suggestion to generate a short mainline continuation with the shortest path to mate (if DTM is available):

Alternatively, how about always just doing sth like 5 /standard requests in sequence? It's a little bit of HTTP overhead, but avoids the expensive full mainline probes and works with the existing limits.