Poprawiono liczenie krokow, usunieto bug z powtarzaniem algorytmu
This commit is contained in:
parent
5c50c54e46
commit
a605f7a87e
@ -42,24 +42,32 @@ class GC(Cell):
|
||||
x = self.x
|
||||
y = self.y
|
||||
result = []
|
||||
element_list=[]
|
||||
house_count_after_search=house_count
|
||||
for home in range(house_count):
|
||||
avalible_moves = check_moves(enviromnent, x,y)
|
||||
if mode == "DFS":
|
||||
[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],House)
|
||||
house,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],House)
|
||||
elif mode == "BFS":
|
||||
[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],House)
|
||||
house,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],House)
|
||||
self.moves.extend(result)
|
||||
element_list.append(house)
|
||||
|
||||
for dump in range(dump_count):
|
||||
avalible_moves = check_moves(enviromnent, x,y)
|
||||
if mode == "DFS":
|
||||
[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],Dump)
|
||||
dump,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],Dump)
|
||||
elif mode == "BFS":
|
||||
[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],Dump)
|
||||
dump,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],Dump)
|
||||
self.moves.extend(result)
|
||||
element_list.append(dump)
|
||||
for x in element_list:
|
||||
x.unvisited = True
|
||||
self.moves.reverse()
|
||||
|
||||
|
||||
|
||||
|
||||
def make_actions_from_list(self,environment):
|
||||
now = pygame.time.get_ticks()
|
||||
if len(self.moves)==0 or now - self.old_time <= DELAY:
|
||||
|
@ -40,7 +40,8 @@ def BFS(grid, available_movement, gc_moveset, mode):
|
||||
x,y = gc_moveset_state[-1]
|
||||
if(object_in_area):
|
||||
gc_moveset_state.append("pick_garbage")
|
||||
return ([x,y], gc_moveset_state)
|
||||
gc_moveset_state=gc_moveset_state[1::]
|
||||
return (cell,[x,y], gc_moveset_state)
|
||||
|
||||
for direction in avalible_movement_state:
|
||||
x_next, y_next = movement(grid,x,y)[0][direction]
|
||||
|
@ -25,7 +25,7 @@ def DFS(grid, available_movement, gc_moveset, mode,depth=0):
|
||||
x,y = gc_moveset[-1]
|
||||
if(object_in_area):
|
||||
gc_moveset.append("pick_garbage")
|
||||
return ([x,y], gc_moveset)
|
||||
return (cell,[x,y], gc_moveset)
|
||||
|
||||
if len(available_movement) == 0 or depth>30:
|
||||
return
|
||||
@ -35,5 +35,6 @@ def DFS(grid, available_movement, gc_moveset, mode,depth=0):
|
||||
gc_moveset_next = gc_moveset.copy()
|
||||
gc_moveset_next.append([x_next,y_next])
|
||||
result = DFS(grid, available_movement_next, gc_moveset_next,mode, depth+1)
|
||||
result[2]=result[2][1::]
|
||||
if result!= None:
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user