Dzialajacy DFS
This commit is contained in:
parent
3b6fc6a446
commit
c5ed2423d6
@ -1,7 +1,9 @@
|
|||||||
from utilities import movement,check_moves
|
from utilities import movement,check_moves
|
||||||
from DataModels.House import House
|
from DataModels.House import House
|
||||||
from DataModels.Container import Container
|
from DataModels.Container import Container
|
||||||
def DFS(grid, available_movement, gc_moveset, depth=0):
|
stack = []
|
||||||
|
def visit_cell(grid, available_movement, gc_moveset, depth=0):
|
||||||
|
global stack
|
||||||
possible_goals = []
|
possible_goals = []
|
||||||
a = gc_moveset[-1][0]
|
a = gc_moveset[-1][0]
|
||||||
b = gc_moveset[-1][1]
|
b = gc_moveset[-1][1]
|
||||||
@ -10,28 +12,35 @@ def DFS(grid, available_movement, gc_moveset, depth=0):
|
|||||||
possible_goals.append([a,b+1])
|
possible_goals.append([a,b+1])
|
||||||
possible_goals.append([a,b-1])
|
possible_goals.append([a,b-1])
|
||||||
house_in_area = False
|
house_in_area = False
|
||||||
|
|
||||||
for location in possible_goals:
|
for location in possible_goals:
|
||||||
try:
|
try:
|
||||||
if(type(grid[location[0]][location[1]]) == House and grid[location[0]][location[1]].container.is_full
|
cell = grid[location[0]][location[1]]
|
||||||
and grid[location[0]][location[1]].unvisited):
|
if(type(cell) == House and cell.container.is_full and cell.unvisited):
|
||||||
grid[location[0]][location[1]].unvisited = False
|
cell.unvisited = False
|
||||||
house_in_area = True
|
house_in_area = True
|
||||||
print("dupa")
|
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
if(house_in_area):
|
||||||
if(house_in_area or len(available_movement) == 0):
|
|
||||||
print("Do zwrocenia: ",gc_moveset)
|
|
||||||
xy = gc_moveset[-1]
|
xy = gc_moveset[-1]
|
||||||
print(available_movement)
|
|
||||||
gc_moveset.append("pick_garbage")
|
gc_moveset.append("pick_garbage")
|
||||||
return (xy, gc_moveset)
|
return (xy, gc_moveset)
|
||||||
|
|
||||||
|
if len(available_movement) == 0 or depth>30:
|
||||||
|
return
|
||||||
x,y = gc_moveset[-1]
|
x,y = gc_moveset[-1]
|
||||||
for direction in available_movement:
|
for direction in available_movement:
|
||||||
x_next, y_next = movement(grid,x,y)[0][direction]
|
x_next, y_next = movement(grid,x,y)[0][direction]
|
||||||
available_movement_next = check_moves(grid, x_next,y_next,direction)
|
available_movement_next = check_moves(grid, x_next,y_next,direction)
|
||||||
gc_moveset_next = gc_moveset.copy()
|
gc_moveset_next = gc_moveset.copy()
|
||||||
gc_moveset_next.append([x_next,y_next])
|
gc_moveset_next.append([x_next,y_next])
|
||||||
return DFS(grid, available_movement_next, gc_moveset_next)
|
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
|
||||||
|
2
main.py
2
main.py
@ -69,7 +69,7 @@ for line in map_objects:
|
|||||||
for item in line:
|
for item in line:
|
||||||
pygame_sprites.add(item)
|
pygame_sprites.add(item)
|
||||||
|
|
||||||
gc = GC(GC_X, GC_Y, 20)
|
gc = GC(GC_X, GC_Y, 200)
|
||||||
print("GC: " + str(GC_X) + str(GC_Y))
|
print("GC: " + str(GC_X) + str(GC_Y))
|
||||||
pygame_sprites.add(gc)
|
pygame_sprites.add(gc)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user