peterosterlund2 / texel

Texel chess engine
GNU General Public License v3.0
33 stars 4 forks source link

Exit proofgame after it finds a list of moves leading to a position #5

Open dpaleka opened 1 year ago

dpaleka commented 1 year ago

Is there an option for telexutil proofgame to say whether it found a list of moves leading to a given position?

For example, when I run

texelutil proofgame -w 1:5 -v -nokernel \ 
    "r6r/pp3pk1/5Rp1/n2pP1Q1/2pPp3/2P1P2q/PP1B3P/R5K1 w - - 0 1"

I get some log like this:

min cost: 24 queue: 0 nodes: 0 time: 8.50001e-06
Q:0 R:0 Bd:0 Bl:-1 N:-2 P:-1 sP:1
q:0 r:0 bd:-1 bl:-1 n:-1 p:-1 sp:1
bound: 12 -w 1:5 queue: 305 nodes: 13 time: 0.00338529
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4
min cost: 26 queue: 356 nodes: 15 time: 0.00377876
bound: 10 -w 1:5 queue: 4475 nodes: 198 time: 0.0298678
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6
min cost: 28 queue: 4500 nodes: 199 time: 0.0300857
bound: 8 -w 1:5 queue: 8052 nodes: 343 time: 0.0520785
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6 Nf3 Qc8 Kg1 Bb4
min cost: 30 queue: 8368 nodes: 357 time: 0.0540554
bound: 7 -w 1:5 queue: 14481 nodes: 654 time: 0.0909689
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6 Nf3 Qc8 Kg1 Bd6 g3 Bf4 gxf4
min cost: 32 queue: 14523 nodes: 656 time: 0.0913092
min cost: 34 queue: 15920 nodes: 728 time: 0.100409
bound: 6 -w 1:5 queue: 15997 nodes: 731 time: 0.10089
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6 Nf3 Qc8 Kg1 Bd6 g3 Bf4 gxf4 Kf8 Ne5 Nxe5 Bf3 Kg7
min cost: 36 queue: 16420 nodes: 750 time: 0.103554
bound: 5 -w 1:5 queue: 16490 nodes: 753 time: 0.103966
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6 Nf3 Qc8 Kg1 Bd6 g3 Bf4 gxf4 Kf8 Ne5 Nxe5 Bf3 Kg7 fxe5 Ne7 Bh5
min cost: 38 queue: 16623 nodes: 758 time: 0.104789
bound: 4 -w 1:5 queue: 16686 nodes: 761 time: 0.105167
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6 Nf3 Qc8 Kg1 Bd6 g3 Bf4 gxf4 Kf8 Ne5 Nxe5 Bf3 Kg7 fxe5 Ne7 Bg4 Bxg4 f4 Nc6
min cost: 40 queue: 16784 nodes: 765 time: 0.10579
min cost: 42 queue: 19295 nodes: 890 time: 0.117835
min cost: 44 queue: 145429 nodes: 7531 time: 0.725356
bound: 2 -w 1:5 queue: 146555 nodes: 7585 time: 0.728636
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6 Nf3 Qc8 Kg1 Bd6 g3 Bf4 gxf4 Kf8 Ne5 Nxe5 Bf3 Kg7 fxe5 Ne7 Bh5 Nc6 Bxg6 hxg6 f3 Bg4 Na3 Bxf3 Rf1 Bg2 Rf6 Na5
min cost: 46 queue: 146574 nodes: 7586 time: 0.728826
min cost: 48 queue: 147366 nodes: 7622 time: 0.731002
min cost: 50 queue: 179351 nodes: 9233 time: 0.821918
min cost: 52 queue: 298779 nodes: 16436 time: 1.1709
bound: 1 -w 1:5 queue: 13625768 nodes: 943040 time: 55.6623
d4 c5 c3 d5 e3 e5 Qg4 g6 Bd2 c4 Qg5 e4 Be2 Bd7 Kf1 Nc6 Nf3 Qc8 Kg1 Bd6 g3 Bf4 gxf4 Kf8 Ne5 N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and. For my use case, it seems I have to parse the output and check whether any list of moves in the output is a solution. Note that I am not interested in the number of moves reaching a given position; that's why I put 0 1, as in the example in proofgame.md.

peterosterlund2 commented 1 year ago

There is "texelutil proofgame -f ..." which provides a more automatic way of finding proof games for possibly large number of positions. It is optimized for random positions though. For example, assuming bash shell:

$ echo "r6r/pp3pk1/5Rp1/n2pP1Q1/2pPp3/2P1P2q/PP1B3P/R5K1 w - - 0 1" | texelutil proofgame -f -o result 2>debug | tee status
legal: 0 path: 0 kernel: 1 fail: 0 illegal: 0 time: 10.443
legal: 0 path: 1 kernel: 0 fail: 0 illegal: 0 time: 10.951
legal: 1 path: 0 kernel: 0 fail: 0 illegal: 0 time: 11.005
$ cat result02 
r6r/pp3pk1/5Rp1/n2pP1Q1/2pPp3/2P1P2q/PP1B3P/R5K1 w - - 0 1 legal: proof: g4 d5 f4 h5 gxh5 e5 Nh3 Bxh3 Bxh3 e4 Bd7+ Nxd7 h6 Ne5 fxe5 Rxh6 Nc3 Be7 Na4 Bc5 Nxc5 Rh8 Ne6 Qc8 Nd8 Qxd8 Kf1 Kf8 d4 c5 c3 g6 e3 c4 Bd2 Kg7 Qh5 Qd7 Qg5 Ne7 Kg1 Nc6 Rf1 Qe6 Rf6 Qh3 Kf2 Rh7 Ra1 Rhh8 Kg1 Na5

If you don't use "-f", there is no way to automatically stop after the first solution is found.

dpaleka commented 1 year ago

Aha, so if I specify -o result, it will create files result00, result01, ..., and if it finds something, the last one will be resultXY, containing the proof. Thanks, this clarifies how to extract the list of moves for a single game.

Is there a performance gain in running proofgame on a file of positions, as opposed to running multiple jobs? I do not understand how to generalize the above if there are multiple games in the input file; but if there aren't any significant performance gains, maybe I can just run many proofgame instances in parallel.

peterosterlund2 commented 1 year ago

If there are multiple positions in the input file there will be multiple lines in the result files. One line for each position.

An advantage of running a single texelutil proofgame instance is that it is easier to control the amount of parallelism and hence the amount of required memory. By default texelutil uses as many threads as there are "hardware threads" in the computer, which typically includes hyperthreads. You can override this using "-j", e.g.:

texelutil -j 4 proofgame -f -o ...

to force using 4 threads.