Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 138bc22

Browse files
antmarakisnorvig
authored andcommitted
Update grid.py (aimacode#531)
1 parent a271ce6 commit 138bc22

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

grid.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,34 @@
66

77
from utils import clip
88

9-
orientations = [(1, 0), (0, 1), (-1, 0), (0, -1)]
9+
orientations = EAST, NORTH, WEST, SOUTH = [(1, 0), (0, 1), (-1, 0), (0, -1)]
10+
turns = LEFT, RIGHT = (+1, -1)
1011

1112

1213
def turn_heading(heading, inc, headings=orientations):
1314
return headings[(headings.index(heading) + inc) % len(headings)]
1415

1516

1617
def turn_right(heading):
17-
return turn_heading(heading, -1)
18+
return turn_heading(heading, RIGHT)
1819

1920

2021
def turn_left(heading):
21-
return turn_heading(heading, +1)
22+
return turn_heading(heading, LEFT)
2223

2324

2425
def distance(a, b):
2526
"""The distance between two (x, y) points."""
26-
return math.hypot((a[0] - b[0]), (a[1] - b[1]))
27+
xA, yA = a
28+
xB, yB = b
29+
return math.hypot((xA - xB), (yA - yB))
2730

2831

2932
def distance_squared(a, b):
3033
"""The square of the distance between two (x, y) points."""
31-
return (a[0] - b[0])**2 + (a[1] - b[1])**2
34+
xA, yA = a
35+
xB, yB = b
36+
return (xA - xB)**2 + (yA - yB)**2
3237

3338

3439
def vector_clip(vector, lowest, highest):

0 commit comments

Comments
 (0)