Skip to content

Commit

Permalink
Rework needs_annotation() to take a judgment
Browse files Browse the repository at this point in the history
rather than a pre-computed delta. This will support more sophisticated
means of judging whether a node needs an annotation or not.
  • Loading branch information
rpdelaney committed Nov 24, 2017
1 parent 4dc4335 commit 3ec8e9f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
22 changes: 12 additions & 10 deletions annotator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ def eval_absolute(number, white_to_move):
return number


def needs_annotation(delta):
def needs_annotation(judgment):
"""
Returns a boolean indicating whether a node with the given evaluations
should have an annotation added
"""
delta = judgment["besteval"] - judgment["playedeval"]

return delta > 50

Expand Down Expand Up @@ -429,10 +430,13 @@ def add_acpl(game, root_node):
while not node == root_node:
prev_node = node.parent

judgment = node.comment
delta = judgment["besteval"] - judgment["playedeval"]

if node.board().turn:
black_cpl.append(cpl(node.comment))
black_cpl.append(cpl(delta))
else:
white_cpl.append(cpl(node.comment))
white_cpl.append(cpl(delta))

node = prev_node

Expand Down Expand Up @@ -543,13 +547,12 @@ def analyze_game(game, arg_time, enginepath):

# Get the engine judgment of the played move in this position
judgment = judge_move(prev_node.board(), node.move, engine, info_handler, time_per_move)
delta = judgment["besteval"] - judgment["playedeval"]

# Record the delta, to be referenced in the second pass
node.comment = str(delta)
node.comment = judgment

# Count the number of mistakes that will have to be annotated later
if needs_annotation(delta):
if needs_annotation(judgment):
error_count += 1

# Print some debugging info
Expand Down Expand Up @@ -593,15 +596,14 @@ def analyze_game(game, arg_time, enginepath):
while not node == root_node:
prev_node = node.parent

delta = int(node.comment)
judgment = node.comment

if needs_annotation(delta):
if needs_annotation(judgment):
# Get the engine judgment of the played move in this position
judgment = judge_move(prev_node.board(), node.move, engine, info_handler, time_per_move)

# Verify that the engine still dislikes the played move
delta = judgment["besteval"] - judgment["playedeval"]
if needs_annotation(delta):
if needs_annotation(judgment):
add_annotation(node, judgment)
else:
node.comment = None
Expand Down
30 changes: 24 additions & 6 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,45 @@ def test_cp_negative(self):
class test_needs_annotation(unittest.TestCase):

def test_high(self):
result = annotator.needs_annotation(100)
judgment = {}
judgment["besteval"] = 200
judgment["playedeval"] = 100
result = annotator.needs_annotation(judgment)
self.assertTrue(result)

def test_low(self):
result = annotator.needs_annotation(5)
judgment = {}
judgment["besteval"] = 5
judgment["playedeval"] = 0
result = annotator.needs_annotation(judgment)
self.assertFalse(result)

def test_negative(self):
result = annotator.needs_annotation(-100)
judgment = {}
judgment["besteval"] = 0
judgment["playedeval"] = 100
result = annotator.needs_annotation(judgment)
self.assertFalse(result)

def test_zero(self):
result = annotator.needs_annotation(0)
judgment = {}
judgment["besteval"] = 0
judgment["playedeval"] = 0
result = annotator.needs_annotation(judgment)
self.assertFalse(result)

def test_low_fraction(self):
result = annotator.needs_annotation(5.3333333)
judgment = {}
judgment["besteval"] = 5.333333
judgment["playedeval"] = 0
result = annotator.needs_annotation(judgment)
self.assertFalse(result)

def test_high_fraction(self):
result = annotator.needs_annotation(500.33333)
judgment = {}
judgment["besteval"] = 500.33333
judgment["playedeval"] = 0
result = annotator.needs_annotation(judgment)
self.assertTrue(result)

def test_raises_typeerror(self):
Expand Down

0 comments on commit 3ec8e9f

Please sign in to comment.