python-chess-annotator icon indicating copy to clipboard operation
python-chess-annotator copied to clipboard

ZeroDivisionError: float division by zero -- seems to be a different one from reported previously

Open lazydroid opened this issue 4 years ago • 12 comments

This happened for the game downloaded from lichess, it had a proper PGN header, but the game was "1. e4 e6 0-1" -- that's it, white resigned.

An unhandled exception occurred: <class 'ZeroDivisionError'>
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 811, in <module>
    main()
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 801, in main
    raise e
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 794, in main
    engine, args.threads)
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 655, in analyze_game
    time_per_move = get_time_per_move(pass1_budget, ply_count)
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 543, in get_time_per_move
    return float(pass_budget) / float(ply_count)
ZeroDivisionError: float division by zero

lazydroid avatar Jan 17 '21 19:01 lazydroid

python-chess-annotator skips moves it finds in its opening book, but it has no logic to detect situations where the game ended before the main line was out of book (and therefore no analysis is necessary). I believe that is the cause of this error. Simply returning if ply_count <= 0 may be enough to fix this.

rpdelaney avatar Jan 19 '21 19:01 rpdelaney

ok, here's another one, more recent, basically you have a ZeroDivision happening inside the exception handler of another ZeroDivision. I don't understand why you need all this "precise" time allocation per error_count, ply_count or whatever. because it's natural that 60-moves games should take 3x as long to annotate compared to a 20-moves game.

So what I did is replaced the *_count variable (in all those budget / some_count statements) with the exact number 20 -- the average number of moves in a game. Yes, it might take a bit longer sometimes, but generally I got rid of all those pesky "ZeroDivision" exceptions once and for all. Would recommend you doing the same =)

An unhandled exception occurred: <class 'ZeroDivisionError'>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 701, in analyze_game
    time_per_move = pass2_budget / error_count
ZeroDivisionError: float division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 811, in <module>
    main()
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 801, in main
    raise e
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 794, in main
    engine, args.threads)
  File "/usr/local/lib/python3.6/dist-packages/annotator/__main__.py", line 705, in analyze_game
    time_per_move = pass2_budget / ply_count
ZeroDivisionError: float division by zero

lazydroid avatar Jan 29 '21 14:01 lazydroid

I'm no longer developing this app, as is evinced by its archived status. If I do a rewrite, it will be from scratch, and I will be disinclined to abandon the time budgeting features (although they would have more rigorous tests).

rpdelaney avatar Jan 29 '21 16:01 rpdelaney

FYI I am working on a rewrite. Not sure when it will be publication ready though.

rpdelaney avatar Apr 04 '21 15:04 rpdelaney

@rpdelaney do you use any repo for the development? need any help? i can lend a hand...

lazydroid avatar Apr 20 '21 13:04 lazydroid

Thanks for offering. It's here, currently in what I would call an "MVP" state. I don't want to publish it to pypi until it's on par with the features of the original though. Please discuss with me if you plan to do a lot of work on it since I have some rather opinionated ideas in my head about how I'd like the end product to look. There are also a lot of new features in python-chess to take advantage of this time around.

rpdelaney avatar Apr 20 '21 16:04 rpdelaney

Thanks for the hard work on this - it promises to be such a useful tool

DocToime avatar Apr 25 '21 17:04 DocToime

What are folks using this for? The original version was just a project to teach myself python. With free analysis tools out there like on lichess.org what niche is this filling?

rpdelaney avatar Apr 25 '21 22:04 rpdelaney

Hi Ryan, I've got a pgn containing all my online games - what I want to do is analyse the positions in all of them to identify my mistakes or missed opportunities of various severity and use the FENs of those positions to generate training puzzles for myself to improve. Coding is not my forte, but your tool is the closest thing I've found to facilitate the first game analysis and annotation part of this, and suspect I can then muddle through writing code to do the rest. If I'm missing a trick and there's already a tool that can do this, any pointers much appreciated!

DocToime avatar Apr 26 '21 09:04 DocToime

If what you want is tactics, there are some tools that can accomplish this for you I believe, although I haven't used any of them (yet). lichess-puzzler was I think used to make the new batch of lichess puzzles (it's based on a very primitive script I wrote but ornicar improved it immensely). There's also chess artist and a few others that come up if you just search github for "chess puzzle".

If I were you I would be thinking more about one of these tools for generating puzzles. The problem with chess-annotator is that it only shows one line of best play when there may be transposing lines or other different-but-equally-good ways to play.

I'm still going to work on annotator-ng as time and energy permits, mind you.

rpdelaney avatar Apr 26 '21 14:04 rpdelaney

Oh hey, look at this!

rpdelaney avatar Apr 26 '21 14:04 rpdelaney

With free analysis tools out there like on lichess.org what niche is this filling?

@rpdelaney i have a few thousands games of mine over the last couple of years, I'd like to analyze them once and for all, not copy-pasting to some web-site one by one and worrying about hitting some limit of 10 analyses a day (like on lichess).

besides, occasionally I'd like to get a fresh game collection from the net and search it for some particular things that interest me, you may call it tactics, but with some additional requirements and/or conditions.

lazydroid avatar May 08 '21 10:05 lazydroid