2019-04-23 17:15:05 +02:00
|
|
|
from utilities import movement,check_moves
|
2019-04-23 20:48:14 +02:00
|
|
|
from DataModels.House import House
|
2019-04-23 21:45:16 +02:00
|
|
|
from DataModels.Container import Container
|
2019-04-23 23:05:34 +02:00
|
|
|
stack = []
|
|
|
|
def visit_cell(grid, available_movement, gc_moveset, depth=0):
|
|
|
|
global stack
|
2019-04-23 20:48:14 +02:00
|
|
|
possible_goals = []
|
|
|
|
a = gc_moveset[-1][0]
|
|
|
|
b = gc_moveset[-1][1]
|
|
|
|
possible_goals.append([a+1,b])
|
|
|
|
possible_goals.append([a-1,b])
|
|
|
|
possible_goals.append([a,b+1])
|
|
|
|
possible_goals.append([a,b-1])
|
|
|
|
house_in_area = False
|
|
|
|
for location in possible_goals:
|
|
|
|
try:
|
2019-04-23 23:05:34 +02:00
|
|
|
cell = grid[location[0]][location[1]]
|
|
|
|
if(type(cell) == House and cell.container.is_full and cell.unvisited):
|
|
|
|
cell.unvisited = False
|
2019-04-23 20:48:14 +02:00
|
|
|
house_in_area = True
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
continue
|
2019-04-23 23:05:34 +02:00
|
|
|
if(house_in_area):
|
2019-04-23 21:45:16 +02:00
|
|
|
xy = gc_moveset[-1]
|
|
|
|
gc_moveset.append("pick_garbage")
|
|
|
|
return (xy, gc_moveset)
|
2019-04-23 23:05:34 +02:00
|
|
|
|
|
|
|
if len(available_movement) == 0 or depth>30:
|
|
|
|
return
|
2019-04-10 11:18:22 +02:00
|
|
|
x,y = gc_moveset[-1]
|
2019-04-23 21:45:16 +02:00
|
|
|
for direction in available_movement:
|
2019-04-23 17:15:05 +02:00
|
|
|
x_next, y_next = movement(grid,x,y)[0][direction]
|
2019-04-23 21:45:16 +02:00
|
|
|
available_movement_next = check_moves(grid, x_next,y_next,direction)
|
2019-04-23 17:15:05 +02:00
|
|
|
gc_moveset_next = gc_moveset.copy()
|
|
|
|
gc_moveset_next.append([x_next,y_next])
|
2019-04-23 23:05:34 +02:00
|
|
|
stack.append([grid, available_movement_next, gc_moveset_next, depth+1])
|
|
|
|
|
|
|
|
def DFS(grid, available_movement, gc_moveset, depth=0):
|
|
|
|
global stack
|
|
|
|
stack.append([grid, available_movement, gc_moveset, 0])
|
|
|
|
while not len(stack)==0:
|
|
|
|
state = stack.pop()
|
|
|
|
result = visit_cell(state[0], state[1], state[2],state[3])
|
|
|
|
if result!= None:
|
|
|
|
return result
|