Added patch to allow app to even start
This commit is contained in:
parent
265668fa47
commit
b7d463f0ec
@ -104,7 +104,9 @@ class GC(Cell):
|
|||||||
|
|
||||||
for i in range(len(houses_list)):
|
for i in range(len(houses_list)):
|
||||||
available_movement = check_moves(environment, x, y)
|
available_movement = check_moves(environment, x, y)
|
||||||
[x,y],result,houses_list = BestFS(environment, available_movement, [[x,y]], houses_list)
|
output = BestFS(environment, available_movement, [[x,y]], houses_list)
|
||||||
|
if(output != None):
|
||||||
|
[x,y],result,houses_list = output[0], output[1], output[2]
|
||||||
self.moves.extend(result[1:])
|
self.moves.extend(result[1:])
|
||||||
self.moves.reverse()
|
self.moves.reverse()
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@ def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
|
|||||||
x, y = gc_moveset[-1][0], gc_moveset[-1][1]
|
x, y = gc_moveset[-1][0], gc_moveset[-1][1]
|
||||||
|
|
||||||
#if depth exceeded, return
|
#if depth exceeded, return
|
||||||
if(depth > 30 or len(available_movement) == 0):
|
if(depth > 15 or len(available_movement) == 0):
|
||||||
return
|
return
|
||||||
|
|
||||||
#calculate distance to the nearest object
|
#calculate distance to the nearest object
|
||||||
min_distance_goal = CalculateDistance([x,y], object_list)
|
min_distance_goal = CalculateDistance([x,y], object_list)
|
||||||
print(min_distance_goal)
|
print(depth,min_distance_goal)
|
||||||
|
|
||||||
if(min_distance_goal[1] == 1):
|
if(min_distance_goal[1] == 1):
|
||||||
gc_moveset.append("pick_garbage")
|
gc_moveset.append("pick_garbage")
|
||||||
@ -64,7 +64,7 @@ def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
|
|||||||
sorted.extend(available_movement)
|
sorted.extend(available_movement)
|
||||||
available_movement = sorted.copy()
|
available_movement = sorted.copy()
|
||||||
|
|
||||||
#print("After sorting: "+str(available_movement))
|
print("After sorting: "+str(available_movement))
|
||||||
|
|
||||||
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]
|
||||||
|
@ -1,84 +0,0 @@
|
|||||||
from utilities import movement,check_moves
|
|
||||||
from DataModels.House import House
|
|
||||||
from DataModels.Container import Container
|
|
||||||
from config import GRID_WIDTH, GRID_HEIGHT
|
|
||||||
from math import sqrt
|
|
||||||
INF = float('Inf')
|
|
||||||
|
|
||||||
|
|
||||||
def CalculateDistance(gc, goal):
|
|
||||||
result = sqrt(pow(goal[0]-gc[0],2)+pow(goal[1]-gc[1],2))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def BestFS(grid, available_movement, gc_moveset, houses_list, mode = "House", depth=0):
|
|
||||||
|
|
||||||
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])
|
|
||||||
object_in_area = False
|
|
||||||
for location in possible_goals:
|
|
||||||
if GRID_WIDTH>location[0]>=0 and GRID_HEIGHT>location[1]>=0:
|
|
||||||
cell = grid[location[0]][location[1]]
|
|
||||||
if mode == "House":
|
|
||||||
if(type(cell) == House and cell.container.is_full and cell.unvisited):
|
|
||||||
cell.unvisited = False
|
|
||||||
object_in_area = True
|
|
||||||
print("***"+str([cell,location])+"***")
|
|
||||||
houses_list.remove([cell,location])
|
|
||||||
break
|
|
||||||
elif mode == "Dump":
|
|
||||||
if(type(cell) == Dump and cell.unvisited):
|
|
||||||
cell.unvisited = False
|
|
||||||
object_in_area = True
|
|
||||||
break
|
|
||||||
if(object_in_area):
|
|
||||||
xy = gc_moveset[-1]
|
|
||||||
gc_moveset.append("pick_garbage")
|
|
||||||
return (xy, gc_moveset)
|
|
||||||
|
|
||||||
if len(available_movement) == 0 or depth>30:
|
|
||||||
return
|
|
||||||
|
|
||||||
x,y = gc_moveset[-1]
|
|
||||||
|
|
||||||
print([x,y])
|
|
||||||
print(houses_list)
|
|
||||||
#calculate distance to the nearest object
|
|
||||||
min_distance_goal = ['-',INF]
|
|
||||||
for h in houses_list:
|
|
||||||
distance = CalculateDistance([a,b],h[1])
|
|
||||||
if(min_distance_goal[1] > distance):
|
|
||||||
min_distance_goal = [h[1], distance]
|
|
||||||
print(min_distance_goal)
|
|
||||||
|
|
||||||
#set preffered directions based on the closest object
|
|
||||||
preffered_directions = []
|
|
||||||
if(min_distance_goal[0][0] >= a):
|
|
||||||
preffered_directions.append("right")
|
|
||||||
if(min_distance_goal[0][0] <= a):
|
|
||||||
preffered_directions.append("left")
|
|
||||||
if(min_distance_goal[0][1] >= b):
|
|
||||||
preffered_directions.append("down")
|
|
||||||
if(min_distance_goal[0][1] <= b):
|
|
||||||
preffered_directions.append("up")
|
|
||||||
print(preffered_directions)
|
|
||||||
print(available_movement)
|
|
||||||
print("=")
|
|
||||||
output_list = available_movement.copy()
|
|
||||||
output_list = output_list.sort(key=lambda x: preffered_directions.index(x))
|
|
||||||
print(output_list)
|
|
||||||
print("------------------------------")
|
|
||||||
|
|
||||||
|
|
||||||
for direction in available_movement:
|
|
||||||
x_next, y_next = movement(grid,x,y)[0][direction]
|
|
||||||
available_movement_next = check_moves(grid, x_next,y_next,direction)
|
|
||||||
gc_moveset_next = gc_moveset.copy()
|
|
||||||
gc_moveset_next.append([x_next,y_next])
|
|
||||||
result = BestFS(grid, available_movement_next, gc_moveset_next, houses_list, "House", depth+1)
|
|
||||||
if result!= None:
|
|
||||||
return result
|
|
@ -1,96 +0,0 @@
|
|||||||
from utilities import movement,check_moves
|
|
||||||
from DataModels.House import House
|
|
||||||
from DataModels.Container import Container
|
|
||||||
from config import GRID_WIDTH, GRID_HEIGHT
|
|
||||||
from math import sqrt
|
|
||||||
INF = float('Inf')
|
|
||||||
|
|
||||||
|
|
||||||
def CalculateDistance(gc, houses_list):
|
|
||||||
min_distance_goal = ['-',INF]
|
|
||||||
for h in houses_list:
|
|
||||||
distance = sqrt(pow(h[1][0]-gc[0],2)+pow(h[1][1]-gc[1],2))
|
|
||||||
if(min_distance_goal[1] > distance):
|
|
||||||
min_distance_goal = [h[1], distance]
|
|
||||||
return min_distance_goal
|
|
||||||
|
|
||||||
def BestFS(grid, gc_moveset, houses_list, result, available_movement, mode = "House"):
|
|
||||||
|
|
||||||
#result = [gc_moveset]
|
|
||||||
|
|
||||||
if(len(houses_list) == 0 and depth > 100):
|
|
||||||
return result
|
|
||||||
|
|
||||||
print(gc_moveset)
|
|
||||||
x, y = gc_moveset[0], gc_moveset[1]
|
|
||||||
available_movement = check_moves(grid, x, y)
|
|
||||||
|
|
||||||
constraint = 100
|
|
||||||
while(len(houses_list) > 0 and constraint > 0):
|
|
||||||
|
|
||||||
print("================")
|
|
||||||
print("iteracja: "+str(100-constraint))
|
|
||||||
print("GC: "+str([x,y]))
|
|
||||||
print(houses_list)
|
|
||||||
|
|
||||||
#calculate distance to the nearest object
|
|
||||||
min_distance_goal = CalculateDistance([x,y], houses_list)
|
|
||||||
print(min_distance_goal)
|
|
||||||
|
|
||||||
#set preffered directions based on the closest object
|
|
||||||
preffered_directions = []
|
|
||||||
discouraged_directions = []
|
|
||||||
if(min_distance_goal[1] == 1):
|
|
||||||
result.append("pick_garbage")
|
|
||||||
cell = grid[min_distance_goal[0][0]][min_distance_goal[0][1]]
|
|
||||||
print("***"+str([cell,min_distance_goal[0]])+"***")
|
|
||||||
houses_list.remove([cell,min_distance_goal[0]])
|
|
||||||
if(len(houses_list)==0):
|
|
||||||
break
|
|
||||||
available_movement = check_moves(grid, x, y)
|
|
||||||
|
|
||||||
min_distance_goal = CalculateDistance([x,y], houses_list)
|
|
||||||
print(min_distance_goal)
|
|
||||||
|
|
||||||
print(min_distance_goal[0])
|
|
||||||
|
|
||||||
|
|
||||||
if(min_distance_goal[0][0] > x):
|
|
||||||
preffered_directions.append("right")
|
|
||||||
if(min_distance_goal[0][0] < x):
|
|
||||||
preffered_directions.append("left")
|
|
||||||
if(min_distance_goal[0][1] > y):
|
|
||||||
preffered_directions.append("down")
|
|
||||||
if(min_distance_goal[0][1] < y):
|
|
||||||
preffered_directions.append("up")
|
|
||||||
|
|
||||||
if(len(preffered_directions) == 1):
|
|
||||||
discouraged_directions.append(movement(grid, x, y)[1][preffered_directions[0]])
|
|
||||||
|
|
||||||
print("Preferred: "+str(preffered_directions))
|
|
||||||
print("Discouraged: "+str(discouraged_directions))
|
|
||||||
print("Available: "+str(available_movement))
|
|
||||||
|
|
||||||
if(len(available_movement) == 0):
|
|
||||||
available_movement = check_moves(grid, x, y)
|
|
||||||
if(len(available_movement)>0):
|
|
||||||
next_move = available_movement[0]
|
|
||||||
for move in available_movement:
|
|
||||||
if (move not in discouraged_directions):
|
|
||||||
next_move = move
|
|
||||||
break
|
|
||||||
for move in preffered_directions:
|
|
||||||
if(move in available_movement):
|
|
||||||
next_move = move
|
|
||||||
break
|
|
||||||
print("Next move: "+str(next_move))
|
|
||||||
x_next, y_next = movement(grid, x, y)[0][next_move]
|
|
||||||
print("Next moving to "+str(x_next)+" "+str(y_next))
|
|
||||||
result.append([x_next,y_next])
|
|
||||||
x, y = x_next, y_next
|
|
||||||
available_movement = check_moves(grid, x, y, next_move)
|
|
||||||
print("------------------------------")
|
|
||||||
|
|
||||||
constraint -= 1
|
|
||||||
|
|
||||||
return result
|
|
Loading…
Reference in New Issue
Block a user