|
13 | 13 | import bisect |
14 | 14 | import re |
15 | 15 | from functools import reduce |
| 16 | +from . grid import * |
16 | 17 |
|
17 | 18 | #______________________________________________________________________________ |
18 | 19 | # Simple Data Structures: infinity, Dict, Struct |
@@ -245,58 +246,6 @@ def clip(x, lowest, highest): |
245 | 246 | """Return x clipped to the range [lowest..highest].""" |
246 | 247 | return max(lowest, min(x, highest)) |
247 | 248 |
|
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))) |
300 | 249 |
|
301 | 250 | #______________________________________________________________________________ |
302 | 251 | # Misc Functions |
|
0 commit comments