This commit is contained in:
Jager72 2024-05-09 14:45:32 +02:00
parent 7b661c34c1
commit f7597b2695
2 changed files with 15 additions and 4 deletions

3
app.py
View File

@ -53,6 +53,8 @@ def initBoard():
cells[9][9].waga = 2
cells[9][8].waga = 10
cells[8][8].waga = 10
cells[prefs.SPAWN_POINT[0]+1][prefs.SPAWN_POINT[1]].waga = 100
cells[prefs.SPAWN_POINT[0]][prefs.SPAWN_POINT[1]-1].waga = 100
cells[9][7].waga = 2
cells[10][6].waga = 2
@ -66,6 +68,7 @@ def draw_grid(window, cells, agent):
pygame.draw.rect(window, cell.color, (i*prefs.CELL_SIZE, j*prefs.CELL_SIZE, prefs.CELL_SIZE, prefs.CELL_SIZE))
if(cells[i][j].interactableItem):
cells[i][j].interactableItem.update(window)
if(not cells[i][j].blocking_movement):
cells[i][j].blit_text(cells[i][j].waga, i*50+6, j*52+6, 12,window)
font = pygame.font.SysFont('Comic Sans MS', 30)
scoreText = font.render("Score: {}".format(str(round(agent.score,2))), 1, (0, 0, 0))

View File

@ -213,6 +213,8 @@ class Agent:
return possible_moves
def calculate_priority(self, el):
return el[0]
def bfs2(self, target_x, target_y):
visited = set()
@ -221,8 +223,8 @@ class Agent:
#print(start_state)
queue = []
heapq.heappush(queue, (0,(start_state, [], 0)))
while queue:
queue.sort(key=self.calculate_priority)
_, que = heapq.heappop(queue)
state, actions, gscore = que
self.xPOM, self.yPOM, self.directionPOM = state
@ -256,9 +258,15 @@ 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)
f_score = gscore + self.heuristic((new_x,new_y), (target_x,target_y))
if (action == 'left' or action == 'right') :
gscore = gscore + 1
else:
gscore = gscore + self.cells[new_x][new_y].waga
heapq.heappush(queue, (f_score, (new_state, new_actions, gscore+1)))
f_score = gscore + self.heuristic((new_x,new_y), (target_x,target_y))
heapq.heappush(queue, (f_score, (new_state, new_actions, gscore)))
return []