small fix

This commit is contained in:
Jager72 2024-05-09 14:04:02 +02:00
parent 713a1e6679
commit 7b661c34c1
2 changed files with 12 additions and 9 deletions

4
app.py
View File

@ -51,7 +51,9 @@ def initBoard():
cells[4][2].interactableItem = Table(cells[4][2], "Table")
cells[9][9].waga = 2
cells[9][8].waga = 2
cells[9][8].waga = 10
cells[8][8].waga = 10
cells[9][7].waga = 2
cells[10][6].waga = 2
cells[7][7].waga = 2

View File

@ -219,23 +219,22 @@ class Agent:
self.directionPOM = self.direction
start_state = (self.current_cell.X, self.current_cell.Y, self.directionPOM)
#print(start_state)
queue = deque([(start_state, [])])
queue = []
heapq.heappush(queue, (0,(start_state, [], 0)))
while queue:
(self.xPOM, self.yPOM, self.directionPOM), actions = queue.popleft()
#print(x," ", y, " ", self.directionPOM, " ", actions)
_, que = heapq.heappop(queue)
state, actions, gscore = que
self.xPOM, self.yPOM, self.directionPOM = state
if self.xPOM == target_x and self.yPOM == target_y:
return actions
if (self.xPOM, self.yPOM, self.directionPOM) in visited:
continue
#print(x," ",y," ",direction)
visited.add((self.xPOM, self.yPOM, self.directionPOM))
possible_moves = self.get_possible_moves()
#print(possible_moves)
for new_direction, action in possible_moves:
new_x, new_y = self.xPOM, self.yPOM
new_actions = actions + [action]
@ -257,8 +256,10 @@ class Agent:
if 0 <= new_x < prefs.GRID_SIZE and 0 <= new_y < prefs.GRID_SIZE \
and not self.cells[new_x][new_y].blocking_movement:
new_state = (new_x, new_y, new_direction)
queue.append((new_state, new_actions))
#print(new_state, " ", new_actions)
f_score = gscore + self.heuristic((new_x,new_y), (target_x,target_y))
gscore = gscore + self.cells[new_x][new_y].waga
heapq.heappush(queue, (f_score, (new_state, new_actions, gscore+1)))
return []