Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lazydroid opened this issue Jan 17, 2021 · 12 comments

Comments

@lazydroid
Copy link

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
@rpdelaney
Copy link
Collaborator

rpdelaney commented Jan 19, 2021

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.

@lazydroid
Copy link
Author

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

@rpdelaney
Copy link
Collaborator

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
Copy link
Collaborator

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

@lazydroid
Copy link
Author

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

@rpdelaney
Copy link
Collaborator

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.

@DocToime
Copy link

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

@rpdelaney
Copy link
Collaborator

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?

@DocToime
Copy link

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!

@rpdelaney
Copy link
Collaborator

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
Copy link
Collaborator

Oh hey, look at this!

@lazydroid
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants