small fix
This commit is contained in:
parent
713a1e6679
commit
7b661c34c1
4
app.py
4
app.py
@ -51,7 +51,9 @@ def initBoard():
|
|||||||
cells[4][2].interactableItem = Table(cells[4][2], "Table")
|
cells[4][2].interactableItem = Table(cells[4][2], "Table")
|
||||||
|
|
||||||
cells[9][9].waga = 2
|
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[9][7].waga = 2
|
||||||
cells[10][6].waga = 2
|
cells[10][6].waga = 2
|
||||||
cells[7][7].waga = 2
|
cells[7][7].waga = 2
|
||||||
|
@ -219,23 +219,22 @@ class Agent:
|
|||||||
self.directionPOM = self.direction
|
self.directionPOM = self.direction
|
||||||
start_state = (self.current_cell.X, self.current_cell.Y, self.directionPOM)
|
start_state = (self.current_cell.X, self.current_cell.Y, self.directionPOM)
|
||||||
#print(start_state)
|
#print(start_state)
|
||||||
queue = deque([(start_state, [])])
|
queue = []
|
||||||
|
heapq.heappush(queue, (0,(start_state, [], 0)))
|
||||||
|
|
||||||
while queue:
|
while queue:
|
||||||
(self.xPOM, self.yPOM, self.directionPOM), actions = queue.popleft()
|
_, que = heapq.heappop(queue)
|
||||||
#print(x," ", y, " ", self.directionPOM, " ", actions)
|
state, actions, gscore = que
|
||||||
|
self.xPOM, self.yPOM, self.directionPOM = state
|
||||||
if self.xPOM == target_x and self.yPOM == target_y:
|
if self.xPOM == target_x and self.yPOM == target_y:
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
if (self.xPOM, self.yPOM, self.directionPOM) in visited:
|
if (self.xPOM, self.yPOM, self.directionPOM) in visited:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#print(x," ",y," ",direction)
|
|
||||||
visited.add((self.xPOM, self.yPOM, self.directionPOM))
|
visited.add((self.xPOM, self.yPOM, self.directionPOM))
|
||||||
|
|
||||||
possible_moves = self.get_possible_moves()
|
possible_moves = self.get_possible_moves()
|
||||||
#print(possible_moves)
|
|
||||||
for new_direction, action in possible_moves:
|
for new_direction, action in possible_moves:
|
||||||
new_x, new_y = self.xPOM, self.yPOM
|
new_x, new_y = self.xPOM, self.yPOM
|
||||||
new_actions = actions + [action]
|
new_actions = actions + [action]
|
||||||
@ -257,8 +256,10 @@ class Agent:
|
|||||||
if 0 <= new_x < prefs.GRID_SIZE and 0 <= new_y < prefs.GRID_SIZE \
|
if 0 <= new_x < prefs.GRID_SIZE and 0 <= new_y < prefs.GRID_SIZE \
|
||||||
and not self.cells[new_x][new_y].blocking_movement:
|
and not self.cells[new_x][new_y].blocking_movement:
|
||||||
new_state = (new_x, new_y, new_direction)
|
new_state = (new_x, new_y, new_direction)
|
||||||
queue.append((new_state, new_actions))
|
f_score = gscore + self.heuristic((new_x,new_y), (target_x,target_y))
|
||||||
#print(new_state, " ", new_actions)
|
gscore = gscore + self.cells[new_x][new_y].waga
|
||||||
|
heapq.heappush(queue, (f_score, (new_state, new_actions, gscore+1)))
|
||||||
|
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user