Commit
·
71c4d7a
1
Parent(s):
03ab354
Upd program syntax
Browse files
app.py
CHANGED
@@ -174,8 +174,7 @@ def astar(start, goal, occ):
|
|
174 |
N8 = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)]
|
175 |
openq = [(0, start)]
|
176 |
g = {start: 0}
|
177 |
-
came = {}
|
178 |
-
visited = set()
|
179 |
H, W = occ.shape
|
180 |
while openq:
|
181 |
_, cur = heapq.heappop(openq)
|
@@ -210,7 +209,7 @@ def astar(start, goal, occ):
|
|
210 |
def knn_path(start, targets, occ):
|
211 |
todo = targets[:]; path=[]
|
212 |
cur = tuple(start)
|
213 |
-
reachable = []; unreachable = []
|
214 |
for t in todo:
|
215 |
seg = astar(cur, tuple(t), occ)
|
216 |
if seg:
|
@@ -484,6 +483,7 @@ def _pipeline(uid,img_path):
|
|
484 |
robot = Robot(SPRITE)
|
485 |
# Robot will be spawn on the closest movable mask to top-left
|
486 |
robot.pos = [spawn_x, spawn_y]
|
|
|
487 |
path, unreachable_targets = knn_path(robot.pos, centres, movable_mask)
|
488 |
objs = [{"pos": p, "col": False, "unreachable": False} for p in centres if p not in unreachable_targets]
|
489 |
objs += [{"pos": p, "col": False, "unreachable": True} for p in unreachable_targets]
|
|
|
174 |
N8 = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)]
|
175 |
openq = [(0, start)]
|
176 |
g = {start: 0}
|
177 |
+
came = {}; visited = set() # Flag visited for path optimization
|
|
|
178 |
H, W = occ.shape
|
179 |
while openq:
|
180 |
_, cur = heapq.heappop(openq)
|
|
|
209 |
def knn_path(start, targets, occ):
|
210 |
todo = targets[:]; path=[]
|
211 |
cur = tuple(start)
|
212 |
+
reachable = []; unreachable = [] # flag unreachable apart
|
213 |
for t in todo:
|
214 |
seg = astar(cur, tuple(t), occ)
|
215 |
if seg:
|
|
|
483 |
robot = Robot(SPRITE)
|
484 |
# Robot will be spawn on the closest movable mask to top-left
|
485 |
robot.pos = [spawn_x, spawn_y]
|
486 |
+
# Unreachable targets flagged
|
487 |
path, unreachable_targets = knn_path(robot.pos, centres, movable_mask)
|
488 |
objs = [{"pos": p, "col": False, "unreachable": False} for p in centres if p not in unreachable_targets]
|
489 |
objs += [{"pos": p, "col": False, "unreachable": True} for p in unreachable_targets]
|