thomas-maeder / popeye

Popeye is a chess problem solving and testing software with strong support for fairy chess and heterodox genres. For more information cf. topic "Popeye (chess)" on http://en.wikipedia.org/
31 stars 14 forks source link

Make intelligent mode more intelligent #301

Open JoshuaGreen opened 3 years ago

JoshuaGreen commented 3 years ago

While using Popeye to assess the soundness of various ser-h=s, I discovered that many of its target positions were simply infeasible, and I suspect that a lot of them can be knocked out automatically.  For example:

It would interesting to implement some such heuristics in the target position generation logic.

JoshuaGreen commented 3 years ago

The second bullet could perhaps be well handled by ignoring the Black pieces and characterizing all reachable positions by:

By just considering pawn moves while allowing captures when necessary, it shouldn't be hard to determine every possible final structure before trying to place the rest of the units (or after, as a quick check before launching into full solving).

JoshuaGreen commented 3 years ago

I've placed proof-of-concept code in optimisations/intelligent/intelligent.c in my forked JoshuaGreen/popeye feature/optimize_intelligent_mode branch.  That code assumes that we're solving a seriesmover without any (other) fairy conditions or pieces in which Black will make some nonzero number of moves followed by White making a single move to reach the target position, possibly with some extra White pieces still around.  (The simplification to the case where White makes all the moves would be straightforward.)

This code is not meant to be taken as-is; it's complicated and it's still undergoing testing, and I could probably better make use of some of Popeye's own functionality.  Also, the best use of these ideas is within the target position generation machinery, not at the end. Rather, some of the ideas might be useful elsewhere, and I primarily want to show the benefits of this approach.  Against one of my own compositions

BeginProblem
    Author Joshua Green
    Origin "StrateGems" -- October-December 2001
    Pieces
        White Kd6 Ba5 Sb5 Pd2e3
        Black Ke1 Pd3e2e4e5f3g4
    Stipulations ser-h=21
    Option intelligent movenumbers
EndProblem

these added heuristics seem to knock out ~ 90% of the generated target positions and provide an associated solving speedup.

JoshuaGreen commented 3 years ago

An extension of this idea would be to perform similar checks in the solving phase after every considered capture, pawn move, and castling (as well as after the first move, if an initial en passant capture was considered).  I'm not sure where/how best to experiment with that.

JoshuaGreen commented 3 years ago

I've continued working on this idea, extending my previous work to also estimate the number of moves needed to reach a target position. The result is my feature/ feature/optimize_intelligent_mode_count_moves branch, and the results seem pretty dramatic — even when compared to my previous version which just checked feasibility — on some problems, e.g.:

BeginProblem
    author Radovan M. Tomasevic and Joshua Green
    origin "StrateGems" January-March 2021
    stipulation ser-h=16
    option intelligent movenumbers
    Pieces
        White Ka4 Qf4 Ra2g1 Ba5b5 Sa1b1
        Black Kh3 Rc8 Bc1f3 Pb2c2c3g2
EndProblem

Assuming that these improvements are real (i.e., there are no bugs that invalidate these timings), I think it's worth trying to get these heuristics into the next release, possibly as an "experimental" option.