lichess-org / scalachess

Chess API written in scala. Immutable and free of side effects.

Home Page:https://lichess.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Win awarded despite forced mate for other side

TheThirdOne opened this issue · comments

I saw #163 and I got wondering if I could make a crazy position where it was a truly forced (ie from both sides) mate and would that be detected.

A little bit later I had made a game to test and found that lichess doesn't detect it correctly and awards a win to black who cannot possibly win if white makes a move.

I don't expect there is an easy solution to this and situations like this probably will never happen in a real game, but I wanted to show that insufficient material rules are not simple to detect.

http://www.e4ec.org/immr.html additionally contains some forced draws which I don't suspect is detected either.

Nice composition!

It seems that correct adjudication (can_win(position, color)) can become arbitrarily complex, so any feasible algorithm will be an approximation. I think we should:

(1) Guarantee there are no false negatives for can_win. It's better to side with the player that did not time out, when we cannot prove a win is impossible.

(2) Keep it simple. For example I like the following rule, aka literally insufficient material:

Looking only at the material configuration, taking into account if pieces bishops are positioned on dark or light squares, but not concrete piece positions, is there a position with the same material configuration where color can win with a series of legal moves. If not, then color has insufficient winning material.

It's straight forward to implement and covers almost everything. (We already do a little bit more than that).

Edit: In particular let's not even attempt getting much simpler forced positions right. E.g. https://syzygy-tables.info/?fen=4k3/4Q3/8/8/8/8/8/4K3_b_-_-_0_1 (black to move loses on timeout, but no sequence of legal moves leads to mate).


cc @ddugovic (who did a lot of work in this area)

I agree on (1) and (2).

FYI I assume Stockfish is one of the more difficult places to implement a complete helpmate (or can_win) solver. Out of scientific curiosity (of just how badly an ideal solver would perform), here's my progress on that so far:
https://github.com/ddugovic/Stockfish/tree/helpmate

Here's an ultra-pathological case where, by FIDE rule 9.7, the game should be an immediate draw — but not only is no checkmate possible, neither is stalemate nor IMM. There's roughly 7 million positions reachable from here and to correctly implement the rule you'd have to search them all.

Screenshot_2019-07-17_23-43-06