-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmazeHTN_operators.py
75 lines (60 loc) · 2 KB
/
mazeHTN_operators.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pyhop
"""
HELPER FUNCTIONS
"""
def already_through(state, a, y, x):
"""Checks if a certain tile has already been traversed through"""
for i in range(state.count[a]):
x1 = state.xpath[a][i]
y1 = state.ypath[a][i]
if x == x1 and y == y1:
return True
return False
"""
OPERATORS
"""
def up(state, a):
"""Check tile above player, walk if criteria met"""
if not state.maze.cell_at(state.x[a], state.y[a]).has_wall('N') and \
(not already_through(state, a, state.y[a] - 1, state.x[a])):
state.y[a] -= 1
state.count[a] += 1
state.xpath[a].append(state.x[a])
state.ypath[a].append(state.y[a])
return state
else:
return False
def down(state, a):
"""Check tile below player, walk if criteria met"""
if not state.maze.cell_at(state.x[a], state.y[a]).has_wall('S') and \
(not already_through(state, a, state.y[a] + 1, state.x[a])):
state.y[a] += 1
state.count[a] += 1
state.xpath[a].append(state.x[a])
state.ypath[a].append(state.y[a])
return state
else:
return False
def left(state, a):
"""Check tile left of player, walk if criteria met"""
if not state.maze.cell_at(state.x[a], state.y[a]).has_wall('W') and \
(not already_through(state, a, state.y[a], state.x[a] - 1)):
state.x[a] -= 1
state.count[a] += 1
state.xpath[a].append(state.x[a])
state.ypath[a].append(state.y[a])
return state
else:
return False
def right(state, a):
"""Check tile right of player, walk if criteria met"""
if not state.maze.cell_at(state.x[a], state.y[a]).has_wall('E') and \
(not already_through(state, a, state.y[a], state.x[a] + 1)):
state.x[a] += 1
state.count[a] += 1
state.xpath[a].append(state.x[a])
state.ypath[a].append(state.y[a])
return state
else:
return False
pyhop.declare_operators(up, down, left, right)