fix
This commit is contained in:
parent
361d08fe91
commit
32fbf3bdf7
@ -13,8 +13,6 @@ class Agent:
|
|||||||
self.cells = cells
|
self.cells = cells
|
||||||
self.score = baseScore
|
self.score = baseScore
|
||||||
self.multiplier = 1
|
self.multiplier = 1
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
|
|
||||||
def move_up(self):
|
def move_up(self):
|
||||||
if pygame.time.get_ticks()-self.last_move_time > 125 and self.current_cell.Y > 0 and not self.cells[self.current_cell.X][self.current_cell.Y-1].blocking_movement:
|
if pygame.time.get_ticks()-self.last_move_time > 125 and self.current_cell.Y > 0 and not self.cells[self.current_cell.X][self.current_cell.Y-1].blocking_movement:
|
||||||
@ -66,36 +64,3 @@ class Agent:
|
|||||||
if self.multiplier < 1:
|
if self.multiplier < 1:
|
||||||
self.multiplier = 1
|
self.multiplier = 1
|
||||||
|
|
||||||
|
|
||||||
def shortest_path(grid, start, end):
|
|
||||||
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
|
|
||||||
rows, cols = len(grid), len(grid[0])
|
|
||||||
|
|
||||||
# Funkcja pomocnicza sprawdzająca, czy dany punkt znajduje się na siatce
|
|
||||||
def is_valid(x, y):
|
|
||||||
return 0 <= x < rows and 0 <= y < cols and grid[x][y] == 0
|
|
||||||
|
|
||||||
# Inicjalizujemy kolejkę BFS i odwiedzone punkty
|
|
||||||
queue = deque([(start, 0)]) # (punkt, odległość)
|
|
||||||
visited = set()
|
|
||||||
|
|
||||||
# Rozpoczynamy BFS
|
|
||||||
while queue:
|
|
||||||
(x, y), distance = queue.popleft()
|
|
||||||
|
|
||||||
# Sprawdzamy, czy osiągnęliśmy punkt docelowy
|
|
||||||
if (x, y) == end:
|
|
||||||
return distance
|
|
||||||
|
|
||||||
# Sprawdzamy wszystkie możliwe kierunki ruchu
|
|
||||||
for dx, dy in directions:
|
|
||||||
nx, ny = x + dx, y + dy
|
|
||||||
|
|
||||||
# Sprawdzamy czy nowa pozycja jest ważna i nieodwiedzona
|
|
||||||
if is_valid(nx, ny) and (nx, ny) not in visited:
|
|
||||||
visited.add((nx, ny))
|
|
||||||
queue.append(((nx, ny), distance + 1))
|
|
||||||
|
|
||||||
# Jeśli nie udało się osiągnąć punktu docelowego, zwracamy -1
|
|
||||||
return -1
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user