FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aima-python/grid.py at master · aesgitrep/aima-python · GitHub
aesgitrep
/
aima-python
Public
forked from
aimacode/aima-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
aima-python
/
grid.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (24 loc) · 1.14 KB
Breadcrumbs
aima-python
/
grid.py
Copy path
File metadata and controls
38 lines (24 loc) · 1.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# OK, the following are not as widely useful utilities as some of the other
# functions here, but they do show up wherever we have 2D grids: Wumpus and
# Vacuum worlds, TicTacToe and Checkers, and markov decision Processes.
# __________________________________________________________________________
import
math
from
utils
import
clip
orientations
=
[(
1
,
0
), (
0
,
1
), (
-
1
,
0
), (
0
,
-
1
)]
def
turn_heading
(
heading
,
inc
,
headings
=
orientations
):
return
headings
[(
headings
.
index
(
heading
)
+
inc
)
%
len
(
headings
)]
def
turn_right
(
heading
):
return
turn_heading
(
heading
,
-
1
)
def
turn_left
(
heading
):
return
turn_heading
(
heading
,
+
1
)
def
distance
(
a
,
b
):
"""The distance between two (x, y) points."""
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."
return
(
a
[
0
]
-
b
[
0
])
**
2
+
(
a
[
1
]
-
b
[
1
])
**
2
def
vector_clip
(
vector
,
lowest
,
highest
):
"""Return vector, except if any element is less than the corresponding
value of lowest or more than the corresponding value of highest, clip to
those values."""
return
type
(
vector
)(
map
(
clip
,
vector
,
lowest
,
highest
))
Back
|
FazBrowse Home
|
New Git URL