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

Skip to content

Commit 79ece42

Browse files
committed
cleaned 2-d grid methods in utils.py as we got them in grid.py
1 parent 2a1c222 commit 79ece42

File tree

1 file changed

+1
-52
lines changed

1 file changed

+1
-52
lines changed

aimaPy/utils.py

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import bisect
1414
import re
1515
from functools import reduce
16+
from . grid import *
1617

1718
#______________________________________________________________________________
1819
# Simple Data Structures: infinity, Dict, Struct
@@ -245,58 +246,6 @@ def clip(x, lowest, highest):
245246
"""Return x clipped to the range [lowest..highest]."""
246247
return max(lowest, min(x, highest))
247248

248-
#______________________________________________________________________________
249-
# OK, the following are not as widely useful utilities as some of the other
250-
# functions here, but they do show up wherever we have 2D grids: Wumpus and
251-
# Vacuum worlds, TicTacToe and Checkers, and markov decision Processes.
252-
253-
orientations = [(1, 0), (0, 1), (-1, 0), (0, -1)]
254-
255-
256-
def turn_heading(heading, inc, headings=orientations):
257-
return headings[(headings.index(heading) + inc) % len(headings)]
258-
259-
260-
def turn_right(heading):
261-
return turn_heading(heading, -1)
262-
263-
264-
def turn_left(heading):
265-
return turn_heading(heading, +1)
266-
267-
268-
def Point(x, y):
269-
return (x, y)
270-
271-
272-
def point_x(point):
273-
return point[0]
274-
275-
276-
def point_y(point):
277-
return point[1]
278-
279-
280-
def distance(a, b):
281-
"The distance between two (x, y) points."
282-
ax, ay = a
283-
bx, by = b
284-
return math.hypot((ax - bx), (ay - by))
285-
286-
287-
def distance2(a, b):
288-
"The square of the distance between two (x, y) points."
289-
ax, ay = a
290-
bx, by = b
291-
return (ax - bx)**2 + (ay - by)**2
292-
293-
294-
def vector_clip(vector, lowest, highest):
295-
"""Return vector, except if any element is less than the corresponding
296-
value of lowest or more than the corresponding value of highest, clip to
297-
those values.
298-
"""
299-
return type(vector)(list(map(clip, vector, lowest, highest)))
300249

301250
#______________________________________________________________________________
302251
# Misc Functions

0 commit comments

Comments
 (0)