Skip to content

Commit f51888a

Browse files
antmarakisnorvig
authored andcommitted
Renamed grid.py Function (aimacode#356)
* Update agents.py * Update test_grid.py * Update grid.py
1 parent 4ae32d8 commit f51888a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

agents.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#
3636
# Speed control in GUI does not have any effect -- fix it.
3737

38-
from grid import distance2, turn_heading
38+
from grid import distance_squared, turn_heading
3939
from statistics import mean
4040

4141
import random
@@ -397,8 +397,8 @@ def things_near(self, location, radius=None):
397397
if radius is None:
398398
radius = self.perceptible_distance
399399
radius2 = radius * radius
400-
return [(thing, radius2 - distance2(location, thing.location)) for thing in self.things
401-
if distance2(location, thing.location) <= radius2]
400+
return [(thing, radius2 - distance_squared(location, thing.location)) for thing in self.things
401+
if distance_squared(location, thing.location) <= radius2]
402402

403403
def percept(self, agent):
404404
"""By default, agent perceives things within a default radius."""

grid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def distance(a, b):
2626
return math.hypot((a[0] - b[0]), (a[1] - b[1]))
2727

2828

29-
def distance2(a, b):
30-
"The square of the distance between two (x, y) points."
29+
def distance_squared(a, b):
30+
"""The square of the distance between two (x, y) points."""
3131
return (a[0] - b[0])**2 + (a[1] - b[1])**2
3232

3333

tests/test_grid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def test_distance():
1010
assert distance((1, 2), (5, 5)) == 5.0
1111

1212

13-
def test_distance2():
14-
assert distance2((1, 2), (5, 5)) == 25.0
13+
def test_distance_squared():
14+
assert distance_squared((1, 2), (5, 5)) == 25.0
1515

1616

1717
def test_vector_clip():

0 commit comments

Comments
 (0)