Giter VIP home page Giter VIP logo

fsmosca / chess-artist Goto Github PK

View Code? Open in Web Editor NEW
66.0 8.0 18.0 45.45 MB

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.

License: GNU General Public License v3.0

Python 98.25% Batchfile 1.75%
python chess game-analyzer script testing-tools epd fen pgn generate-chess-puzzles

chess-artist's People

Contributors

alxlk avatar ddugovic avatar fsmosca avatar huytd avatar kennyfrc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chess-artist's Issues

Add ability to create an EPD test suite.

Parse games in a pgn file, find interesting positions based on some criteria and save it in epd format along with 3 best moves with corresponding points. This is similar to STS but done automatically by the engine. This is primarily intended for testing engines' ability to select top best moves in a position.

Annotation of pgn game with static eval doesn't work for me

It outputs a pgn with no comments like this:


[Event "?"]
[Site "?"]
[Date "2019.03.12"]
[Round "1"]
[White "lc0"]
[Black "lc0"]
[Result "1-0"]
[FEN "8/8/8/4K3/4Q3/8/8/2k5 w - - 0 1"]
[SetUp "1"]
[Annotator "Brainfish 250319 64 POPCNT"]

{Move comments are from engine static evaluation.}
1. Qe2 Kb1 2. Kd4 Kc1 
3. Kc3 Kb1 4. Qb2# 1-0

Add Blunder/Bad counts exceptions

When --player is set, do not show blunder/bad counts for the other player.
Same with --color. If color is white, do not show blunder/bad counts for black and vice versa.

Tune good NAG's according to movetime

  1. Very good (!!)
veryGoodMoveChangesThreshold = 4
if moveTime >= 180000:
    veryGoodMoveChangesThreshold += 2
elif movetime >= 60000:
    veryGoodMoveChangesThreshold += 1
if moveChanges >= veryGoodMoveChangesThreshold 
   moveNag = '$3'

Add --playerandopp option

--playerandopp [player name] is used when you want to analyze the games of player name
as well as its opponent.

--player [player name] is used when you want to analyze the moves
of the player name only.

--player and --playerandopp are mutually exclusive, meaning both options cannot be used
at the same time.

Example:
To analyze moves of Kasparov, Gary and his opponent use --playerandopp
chess-artist.exe --playerandopp "Kasparov, Gary" --infile kasparov_games.pgn --outfile analyzed_games.pgn ...

Calculate position complexity number.

When engine evaluates the move of a player, calculate also its complexity number. Complexity number will be used to annotate moves where the player move is the same as the engine recommended move. The higher the number is the more complex the position is. Depending on this number the player move may get !!, or ! or !?

Analyze test suite to a given depth

When analyzing an epd test suite, is there any way to analyze each position to a certain depth, instead of for n milliseconds? This would make the analysis deterministic and reproducible on different computers.

"ValueError: could not convert string to float: |"

Running the script under linux I get the next error message:

$ python2.7 chess-artist.py --infile lichess_pgn_2019.10.07_pocpit_vs_Stanislavik.ehRhK0vI.pgn --outfile out_sample.pgn --enginefile /usr/games/stockfish --eval search --job analyze --movetime 5000
Analyzing engine: Stockfish 9 64
Annotating game 1...
side: White, move_num: 1
side: Black, move_num: 1
side: White, move_num: 2
side: Black, move_num: 2
side: White, move_num: 3
side: Black, move_num: 3
side: White, move_num: 4
side: Black, move_num: 4
side: White, move_num: 5
side: Black, move_num: 5
side: White, move_num: 6
side: Black, move_num: 6
side: White, move_num: 7
side: Black, move_num: 7
side: White, move_num: 8
Game move: Qxe2 (0.00), Engine bestmove: Qxe2 (0.06)
Traceback (most recent call last):
File "chess-artist.py", line 2395, in
main()
File "chess-artist.py", line 2383, in main
g.AnnotatePgn()
File "chess-artist.py", line 1871, in AnnotatePgn
curFen, side)
File "chess-artist.py", line 962, in IsPassedPawnGood
MgPassedValue = float(passedPawnComment.split()[8])
ValueError: could not convert string to float: |

Add alternative words to "better is" and "excellent is"

  • Alternative to Excellent

    • Exceptional
    • Outstanding
    • Incomparable
    • Priceless
    • Striking
    • Top-notch
    • Splendid
    • Marvellous
    • Brilliant
    • Magnificient
    • Cool
    • Admirable
    • Terrific
  • Alternative to Better

    • More appropriate
    • Worthier
    • Preferable
    • More useful
    • More suitable
    • More fitting
    • More valuable
    • More expert

Limit engine analysis.

Game analysis is consist of 3 parts.

  1. Analyze the move of the player in the game. This is controlled by the option,
    -eval
    with values,
    none, static, search
    -eval static, tells the script to get the evaluation of the player move by engine static evaluation.
    -eval search, tells the script to get the evaluation of the player move by engine search score.
    Example, 1. e4 {+0.10} c5 {+0.10} ...
    If you don't want to evaluate the player move use the option,
    -eval none
    in the command line.
  2. Annotate the player move by cerebellum book moves. This is controlled by the option,
    -book
    with values
    none, cerebellum, polyglot
    Example, 1. Nf3 (1. e4 {cerebellum}) 1... Nf6 (1... d5 {cerebellum}) ...
    To disable it use,
    -book none
    in the command line.
    polyblot option value is not yet implemented.
  3. Annotate the player move with engine best move and score. This is controlled by the option,
    -job
    with values
    none, analyze, test
    By default the -job value is analyze. The test value is used for engine epd testing.
    Example, 6. O-O $0 {-0.61} (6. a3 {cerebellum}) (6. e3 {-0.34 - Brainfish})
    If you don't want to activate it, use
    -job none
    in the command line.

When the evaluation of a player move is already winning +6 pawns or already losing -6 pawns see (1) above, don't analyze the position with engine looking for its recommended move and score output, see (3) above. This will save analysis time for the 3rd part of analysis.

output statistics

Maybe write to the console for each player encountered in the pgn file, how many inaccuracies, mistakes, blunders etc he or she made:

30000 games processed
kasparov, 1 blunders, 3 mistakes, 4 inaccuracies
deepblue, 8 blunders, 1 mistakes, 3 inaccuracies

That way one can use it as an evaluation tool of the strength of e.g. a chess program: make a change, let it play 30k games, count how many bl/mis/inac on average the program made.
Repeat for each new version.
You can then graph or so in e.g. a spreadsheet program the progress.

Add --loss flag

This is used in conjunction with --player or --playerandopp options to only analyze games where the player lost the game.

Release 0.1.0 Check List

PGN analysis

  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval search -book cerebellum -movetime 1000
  • -infile a.pgn -outfile out_a.pgn -eng Sf.exe -eval search -book none -movetime 1000
  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval search -book cerebellum -movetime 1000 -job none
  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval static -book cerebellum -movetime 1000
  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval static -book none -movetime 1000
  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval static -book cerebellum -job none
  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval none -book cerebellum -movetime 1000
  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval none -book none -movetime 1000
  • -infile a.pgn -outfile out_a.pgn -eng Bf.exe -eval none -book cerebellum -job none

EPD analysis

  • -infile a.epd -outfile out_a.epd -eng Bf.exe -eval static
  • -infile a.epd -outfile out_a.epd -eng Bf.exe -eval search -movetime 1000

Engine test

  • -infile wac.epd -outfile out_wac.txt -eng Sf.exe -movetime 1000 -job test

Others

  • Create executable file for windows
  • Improve readme

Python 2

Hi Fsmosca,
Could you please, upgrade Chess-Artist to support Python 3

Enhancement? w/ fix: Linux Doesn't Need Engine in same folder

Sorry, only the second time I've used Git in a number of years, so I'm posting this one-line fix here.

Adding sys.platform check at line 85 allows use of system installation of engine on linux. Not sure if this will create other issues:

    # engine file is missing. Excluding Linux
    if not sys.platform.startswith('linux'): 
        if not os.path.isfile(engfn):
            print('Error! %s is missing' %(engfn))
            sys.exit(1)

Calculate rating difference based average error.

Convert the average error in a game into winning percentage, with winning percentage calculate the rating difference.

To get winning percentage:

y = -(averageError)/4.0
wp = 1.0/(1.0 + (10**y))

To get rating difference:

wp = 1 / (1 + 10**m)
m = ratingDifference/400
ratingDifference = 400 x m

Calculate average move error of the players.

When the engine preferred move is different from the move of the player in the game, calculate the score difference in pawn units between these moves. After the game get the average move error.

Example:
1. e4 e5 2. Nf3 a6 ? {+0.80} (2...Nc6 {+0.05 - Stockfish}) 3. Nxe5 Ba3 ? {+3.5} (3... Qe7 {+0.50 - Stockfish})

  1. Black move error at move 2...
    player_move_error = +0.05 - (+0.80) = -0.75
    since this is black to move we reverse the sign.
    player_move_error = -1 * -0.75 = 0.75
  2. Black move error at move 3...
    player_move_error = +0.50 - (+3.5) = -3.0
    player_move_error = +3.0

Total black move error in 2 moves = 0.75 + 3.0 = 3.75
average = 3.75/2 = 1.875

Don't calculate move errors when the score of the player's move is already winning or losing (+4.0 pawns or more). Calculation of move errors starts at move 12.

The average move error will be appended at the end of the movetext in the notation.
4. bxa3 {WhiteAveError=+0.0, BlackAveError=+1.875} 1-0

crashes always

09:24:39 1d folkert@belle:~/t/chess-artist↥ master* ± python chess-artist.py -infile r.pgn -outfile out_r.pgn -eng ./Embla.sh -eval search -movetime 60000 -movestart 1 -engoptions "Hash value 4096, Threads value 1"
Chess Artist 0.2.0

Analyzing engine: Emblatrunk
Annotating game 1...
Warning, there is error in pvLine
pvLine: ['c8b7', 'o-o', 'b8d7', 'e5d7', 'd8d7']
Traceback (most recent call last):
File "chess-artist.py", line 1805, in
main(sys.argv[1:])
File "chess-artist.py", line 1798, in main
g.AnnotatePgn()
File "chess-artist.py", line 1462, in AnnotatePgn
side)
File "chess-artist.py", line 1010, in GetSearchScoreBeforeMove
return bestMove, scoreP, complexityNumber, moveChanges, pvLineSan
UnboundLocalError: local variable 'pvLineSan' referenced before assignment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.