Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down