diff --git a/app.py b/app.py index 7595735..bdae6b1 100644 --- a/app.py +++ b/app.py @@ -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,7 +68,8 @@ 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) - cells[i][j].blit_text(cells[i][j].waga, i*50+6, j*52+6, 12,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)) multiplierText = font.render("Multiplier: {}".format(str(round(agent.multiplier,2))), 1, (0, 0, 0)) diff --git a/classes/agent.py b/classes/agent.py index 9934be7..ec9ed83 100644 --- a/classes/agent.py +++ b/classes/agent.py @@ -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) + + if (action == 'left' or action == 'right') : + gscore = gscore + 1 + else: + gscore = gscore + self.cells[new_x][new_y].waga + 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))) + + heapq.heappush(queue, (f_score, (new_state, new_actions, gscore))) return []