-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.py
73 lines (52 loc) · 1.78 KB
/
agent.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
import time
class Agent:
"""
initialize some member variables
"""
def __init__(self):
self.player_row = 0
self.player_col = 0
self.level_matrix = None
self.elapsed_solve_time = 0
"""
please use these variables for statistics
"""
self.expanded_node_count = 0
self.generated_node_count = 0
self.maximum_node_in_memory_count = 0
# not implemented, not necessary
self.real_distance_matrix = []
self.manhattan_distance_matrix = []
def count_apples_in_level_matrix(self, level_matrix):
apple_count = sum(row.count("A") for row in level_matrix)
return apple_count
def print_level_matrix(self, level_matrix):
print("")
for row in level_matrix:
print(row)
print("")
"""
level_matrix is list of lists (like 2d array)
that contains whether a particular cell is
-A (apple)
-F (floor)
-P (player)
-W (wall)
level_matrix[0][0] is top left corner
level_matrix[height-1][0] is bottom left corner
level_matrix[height-1][width-1] is bottom right corner
player_row and player_column are current position
of the player, eg:
level_matrix[player_row][player_column] supposed to be P
returns a character list, list of moves
that needs to be played in order to solve
given level
valid letters are R, U, L, D corresponds to:
Right, Up, Left, Down
an example return value:
L = ["U", "U", "U", "L", "R", "R"]...
"""
def solve(self, level_matrix, player_row, player_column):
self.player_row = player_row
self.player_col = player_column
self.level_matrix = level_matrix