fsmosca / chess-artist

A python script that can annotate chess games in pgn file with static evaluation or search score of an engine, can annotate an epd file with acd, acs, bm, and ce opcodes, can test engine with epd test suite and can generate chess puzzles.
GNU General Public License v3.0
69 stars 18 forks source link

Indicate variant in created puzzle EPD #77

Closed ddugovic closed 3 years ago

ddugovic commented 4 years ago

It is possible to generate puzzles from a given PGN file, and that PGN file may contain a chess960 game.

(Also I am working on testing Multi-Variant Stockfish using ddugovic/chess-artist and need to consider how to represent variants such as atomic and atomic960 in EPD format as I manually create test positions.)

fsmosca commented 4 years ago

It is possible to generate puzzles from a given PGN file, and that PGN file may contain a chess960 game.

That is possible. Current version can already annotate chess960 games.

(Also I am working on testing Multi-Variant Stockfish using ddugovic/chess-artist and need to consider how to represent variants such as atomic and atomic960 in EPD format as I manually create test positions.)

Python-chess supports these variants https://python-chess.readthedocs.io/en/latest/variant.html I think this is all possible in chess artist as it is dependent on python-chess.

Not sure about atomic960. Ahh ok, this is atomic board with chess960=True.

Ok I see your modification using the chess.variant module.

fsmosca commented 4 years ago

Added code for Atomic variant for now. https://github.com/fsmosca/chess-artist/commits/variant

See sample output in the comment if engine's comments are reasonable, at https://github.com/fsmosca/chess-artist/commit/4afb28a7a30f6c25d163bd9d09bee0a2c62eb4bb

Output from CreatePuzzle

rq2kb1r/pp6/n1pPp1p1/8/1P5P/P1P2PP1/8/RN1QKB1R b KQkq - bm Qxd6; Ubm b8d6; Ae "Stockfish_2020-06-13_Multi-Variant";
rq3rk1/pp6/n1pPp1pb/8/1P3P1P/P1P3P1/8/RN1QKB1R w KQ - bm Bc4; Ubm f1c4; Ae "Stockfish_2020-06-13_Multi-Variant";
1n6/6k1/8/p5pP/6P1/P7/6B1/7K w - - bm Bf1; Ubm g2f1; Ae "Stockfish_2020-06-13_Multi-Variant";

I add Todo in GameOver(), as every variant could have specific game end rules. I am no longer updated on the rules of some other variants.

There is a note in python-chess.

See chess.Board.is_variant_end(), is_variant_win() is_variant_draw() is_variant_loss() for special
variant end conditions and results.

To let the engine knew of a variant just add UCI_Variant. --engineoptions "Threads value 1, Hash value 128, UCI_Variant value Atomic"

Regarding atomic960 do you have a sample pgn so I can try it?

In the title Indicate variant in created puzzle EPD Do you want to add an opcode? like for example. rq2kb1r/pp6/n1pPp1p1/8/1P5P/P1P2PP1/8/RN1QKB1R b KQkq - bm Qxd6; Ubm b8d6; Ae "Stockfish_2020-06-13_Multi-Variant"; Var atomic; where Var opcode represents variant name.

ddugovic commented 4 years ago

Thanks!! Yes, I am thinking perhaps an opcode may be useful, although maybe a file could only contain EPDs for a single variant? I don't know.

Here is a sample atomic960 PGN (is this format finalized @thomas-daniels @niklasf ?): https://chessvariants.training/Variant960/Game/admkjevn

[Variant "Atomic"]
[FEN "rkrbbnnq/pppppppp/8/8/8/8/PPPPPPPP/RKRBBNNQ w KQkq - 0 1"]
[White "Unihedron"]
[Black "Toadofsky"]
[TimeControl "1800+0"]

1. g3 d5 2. Nf3 e5 3. Ng5 Bxg5 4. Qf3 Ne6 5. Qa3 a5 6. d4 g6 7. c3 h5 8. h4 Qh6 9. Bd2 Qxd2 10. O-O-O e4 11. Ne3 Ba4 12. Rd2 Bb3 13. Qe7 Nxe7 14. axb3 a4 15. Nf5 gxf5 16. g4 a3 17. bxa3 Ra1+ 18. Kb2 Rb1+ 19. Ka2 O-O 20. g5 Ra8# 0-1
fsmosca commented 4 years ago

I prefer opcode, so that it is independent from file naming. I like variant opcode name, it is long but it is clear.

Example: rq2kb1r/pp6/n1pPp1p1/8/1P5P/P1P2PP1/8/RN1QKB1R b KQkq - bm Qxd6; Ubm b8d6; Ae "Stockfish_2020-06-13_Multi-Variant"; variant atomic;

In the example perhaps [Variant "Atomic"] can be made [Variant "Atomic960"] to make the game rule clearer to the user just by reading the Variant tag.

The sf multi-variant can be made aware by sending

setoption name UCI_Chess960 value true
setoption name UCI_Variant value atomic

When chess artist see the tag Atomic960 in the pgn header, it can append variant opcode with value atomic960 when it outputs epd. Example: rkrbbnnq/pppppppp/8/8/8/8/PPPPPPPP/RKRBBNNQ w KQkq - variant atomic960;

thomas-daniels commented 4 years ago

@ddugovic I consider that format finalized, yes, it's that way so it can be immediately imported in a Lichess Study. (Whether it's standardized I don't know, I'm not aware what the other websites offering atomic960 are doing.)

fsmosca commented 4 years ago

Python-chess does not support [Variant "Atomic960"], so for now just use [Variant "Atomic"] and in the command line add, --game960. If that is enabled, the parameter chess960 in python-chess will be set to True. It could then be used in king of the hill chess960, crazyhouse chesss960 and others. See example command line from bat file in variant branch.

Example command line from variant branch. chess_artist.py --game960 --infile PGN/sample_atomic_chess960.pgn --outfile ana_sample_atomic_chess960.pgn --enginefile D:\github\chess-artist\Engine\Stockfish_2020-06-13_Multi-Variant.exe --enginename "Stockfish_multi-variant" --engineoptions "Threads value 1, Hash value 128, UCI_Variant value Atomic, UCI_Chess960 value true" --movestart 2 --movetime 3000 --job analyze --eval search --log

An example output from atomic with game960 option.

[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "Unihedron"]
[Black "Toadofsky"]
[Result "0-1"]
[FEN "rkrbbnnq/pppppppp/8/8/8/8/PPPPPPPP/RKRBBNNQ w KQkq - 0 1"]
[TimeControl "1800+0"]
[Variant "Atomic"]
[Annotator "engine: Stockfish_multi-variant, prog: Chess Artist v2.19"]

{Hash 128mb, Threads 1, analysis 3.0s per position, move score is in pawn unit,
positive is good for white and negative is good for black}
1. g3 d5 2. Nf3 $6 {-0.46} (None {+2.03}) 2... e5 $4 {+1.56} (2...c5 {-0.46}) 
3. Ng5 {-3.86} 3... Bxg5 {+1.88, with a better piece mobility} 
4. Qf3 $2 {-0.15} (4. Qxd5 {+1.88}) 4... Ne6 $4 {+2.07} (4...Nf6 {-0.15}) 
5. Qa3 $2 {-0.80} (None {+2.07}) 5... a5 {-0.66} 
6. d4 $4 {-1.96} (6. d3 c5 7. c4 d4 8. f4 {-0.66}) 6... g6 $2 {+0.09} (6...Nxd4 {-1.85}) 
7. c3 $2 {-1.36} (7. dxe5 Qe5 8. e3 c5 9. f4 {+0.09}) 7... h5 $2 {-0.29} (7...exd4 {-1.36}) 
8. h4 $4 {-1.76} (8. e3 {-0.18}) 8... Qh6 $6 {+0.56} (8...exd4 {-1.76}) 
9. Bd2 $2 {-0.91} (9. dxe5 {+0.56}) 9... Qxd2 $1 {-2.62, white had sacrificed material} (9...Qg7 10. e4 dxe4 11. d5 Nf8 {-0.91}) 
10. O-O-O {-3.02} 10... e4 $2 {-2.41} (10...exd4 {-3.02}) 
11. Ne3 {-3.00} 11... Ba4 $4 {+2.91} (11...Bc6 {-3.00}) 
12. Rd2 $4 {-2.80} (None {+2.91}) 12... Bb3 $4 {+2.90} (12...Bc6 {-2.80}) 
13. Qe7 {-12.48} 13... Nxe7 {-2.77} 
14. axb3 {-4.30} 14... a4 $2 {-2.62} (14...Rd8 15. c4 dxc4 16. Nc4 f6 {-4.30}) 
15. Nf5 {-8.34} 15... gxf5 {-7.78} 16. g4 {-9.77} 16... a3 {-8.85} 
17. bxa3 {-10.27} 17... Ra1+ {-8.96} 18. Kb2 {-9.23} 18... Rb1+ $2 {-1.52} (18...Rf1 {-9.23}) 
19. Ka2 {-9.49} 19... O-O $2 {-2.38} (19...Rf1 {-9.49}) 
20. g5 {-8.65} 20... Ra8# $2 {-0.23} (None {-8.65}) 
{WhiteBlunder=3, BlackBlunder=4, WhiteBad=4, BlackBad=7} 0-1