From a8a281b758516c640d8e4bdb87162ce8247b7054 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Sun, 12 Mar 2017 16:55:42 +0200 Subject: [PATCH 1/3] Update agents.py --- agents.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agents.py b/agents.py index a5bf376ca..742cd6c40 100644 --- a/agents.py +++ b/agents.py @@ -35,7 +35,7 @@ # # Speed control in GUI does not have any effect -- fix it. -from grid import distance2, turn_heading +from grid import distance_squared, turn_heading from statistics import mean import random @@ -397,8 +397,8 @@ def things_near(self, location, radius=None): if radius is None: radius = self.perceptible_distance radius2 = radius * radius - return [(thing, radius2 - distance2(location, thing.location)) for thing in self.things - if distance2(location, thing.location) <= radius2] + return [(thing, radius2 - distance_squared(location, thing.location)) for thing in self.things + if distance_squared(location, thing.location) <= radius2] def percept(self, agent): """By default, agent perceives things within a default radius.""" From 207f69243797890e29137f469f6af3902895181c Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Sun, 12 Mar 2017 16:56:47 +0200 Subject: [PATCH 2/3] Update test_grid.py --- tests/test_grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_grid.py b/tests/test_grid.py index 5e05a617a..928218150 100644 --- a/tests/test_grid.py +++ b/tests/test_grid.py @@ -10,8 +10,8 @@ def test_distance(): assert distance((1, 2), (5, 5)) == 5.0 -def test_distance2(): - assert distance2((1, 2), (5, 5)) == 25.0 +def test_distance_squared(): + assert distance_squared((1, 2), (5, 5)) == 25.0 def test_vector_clip(): From ae17588b844bdaf868fc18c2a5d7840607ee43a4 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Sun, 12 Mar 2017 16:57:14 +0200 Subject: [PATCH 3/3] Update grid.py --- grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid.py b/grid.py index 4400d217b..a7e032136 100644 --- a/grid.py +++ b/grid.py @@ -26,8 +26,8 @@ def distance(a, b): return math.hypot((a[0] - b[0]), (a[1] - b[1])) -def distance2(a, b): - "The square of the distance between two (x, y) points." +def distance_squared(a, b): + """The square of the distance between two (x, y) points.""" return (a[0] - b[0])**2 + (a[1] - b[1])**2