From 9a311a05300f1454e15169745105faa1537e71ab Mon Sep 17 00:00:00 2001 From: NajdorfB <32087643+NajdorfB@users.noreply.github.com> Date: Mon, 14 Oct 2019 12:03:31 +0200 Subject: [PATCH 1/2] Division by zero error if ply_count is zero When running the program, I sometimes ran into two different division by zero problems, caused by the fact that ply_count = 0. My solution is that the minimum of the division with ply_count is 1, so a division by zero is not possible. I suppose it would be better to ensure that ply_count never is zero, but I'm not sure how hard that is as I haven't really looked into the problem. --- annotator/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/annotator/__main__.py b/annotator/__main__.py index c96d8cb..caa4b88 100755 --- a/annotator/__main__.py +++ b/annotator/__main__.py @@ -540,7 +540,7 @@ def get_pass2_budget(total_budget, pass1_budget): def get_time_per_move(pass_budget, ply_count): - return float(pass_budget) / float(ply_count) + return float(pass_budget) / float(max(ply_count, 1)) def analyze_game(game, arg_gametime, enginepath, threads): @@ -702,7 +702,7 @@ def analyze_game(game, arg_gametime, enginepath, threads): except ZeroDivisionError: logger.debug("No errors found on first pass!") # There were no mistakes in the game, so deeply analyze all the moves - time_per_move = pass2_budget / ply_count + time_per_move = pass2_budget / max(ply_count, 1) node = game.end() while not node == root_node: prev_node = node.parent From 56479184635525b4ae760c96d0eecb8f0a13a0b2 Mon Sep 17 00:00:00 2001 From: NajdorfB <32087643+NajdorfB@users.noreply.github.com> Date: Mon, 14 Oct 2019 18:08:54 +0200 Subject: [PATCH 2/2] changed from max to try/error --- annotator/__main__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/annotator/__main__.py b/annotator/__main__.py index caa4b88..0c042e3 100755 --- a/annotator/__main__.py +++ b/annotator/__main__.py @@ -540,7 +540,10 @@ def get_pass2_budget(total_budget, pass1_budget): def get_time_per_move(pass_budget, ply_count): - return float(pass_budget) / float(max(ply_count, 1)) + try: + return float(pass_budget) / float(ply_count) + except ZeroDivisionError: + return 0 def analyze_game(game, arg_gametime, enginepath, threads):