Skip to content

pacman bot#26

Merged
bkrowka merged 6 commits intodevfrom
issue-25
Aug 14, 2025
Merged

pacman bot#26
bkrowka merged 6 commits intodevfrom
issue-25

Conversation

@norbik2004
Copy link
Member

No description provided.

@norbik2004 norbik2004 requested a review from bkrowka July 30, 2025 12:56
@norbik2004 norbik2004 self-assigned this Jul 30, 2025
Copy link
Collaborator

@bkrowka bkrowka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nie analizowałem dokładnie algorytmu bota, ale widać że działa fajnie. Popraw te funkcje zagnieżdżone w metodzie i zwracaj uwagę jak coś jest podkreślane (wiem, że wszystko było praktycznie podkreślone przez jakąś jedną drobną zmianę, ale już to naprawiłem). Jak poprawisz, dodasz typowanie i nie będzie tych ostrzeżeń to merguje.

Copy link
Collaborator

@bkrowka bkrowka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ogólnie o to mi chodziło, ale ze względu na opisany problem na razie nie merguje. Sorki, że nie zwróciłem na to uwagi wcześniej.

src/bots.py Outdated
Comment on lines +173 to +201
def is_walkable(walkable_row: int, walkable_column: int) -> bool:
return (0 <= walkable_row < len(game_map) and 0 <= walkable_column < len(game_map[0])
and game_map[walkable_row][walkable_column] != 1)

def is_safe(safe_row: int, safe_column: int) -> bool:
if not is_walkable(safe_row, safe_column):
return False
if power_mode:
return True
return all(abs(enemy_row - safe_row) + abs(enemy_column - safe_column) > self.safe_distance
for enemy_row, enemy_column in enemies)

def dijkstra_find_path(start_row: int, start_column: int) -> list:
pq = [(0, start_row, start_column, [])]
visited = set()
while pq:
cost, dij_row, dij_column, path = heapq.heappop(pq)
if (dij_row, dij_column) in visited:
continue
visited.add((dij_row, dij_column))
if (dij_row, dij_column) not in self.visited_positions and is_safe(dij_row, dij_column):
self.current_target = (dij_row, dij_column)
return path
for dij_move, (direction_row, direction_column) in directions.items():
next_row, next_column = dij_row + direction_row, dij_column + direction_column
if ((next_row, next_column) not in visited and
is_walkable(next_row, next_column) and is_safe(next_row, next_column)):
heapq.heappush(pq, (cost + 1, next_row, next_column, path + [dij_move]))
return []
Copy link
Collaborator

@bkrowka bkrowka Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wszystko super, o to mi chodziło, ale uświadomiłem sobie o jednym problemie. Metoda choose_move jest wywoływana co około 50 ms (w zależności jak ustawisz interwał na stronie, ten jest domyślny). W związku z tym wszystkie te funkcje zagnieżdżone są definiowane od nowa jakieś 20 razy na sekundę co pewnie znacząco wpływa na wydajność i szybkość zwracania ruchu. Ma to znaczenie w kontekście tego, że przecież mikroserwis uruchamiany jest na serwerze, więc bot może grać dużo gorzej niż powinien ze względu na dodatkowe opóźnienia. Pasuje przenieść je jako osobne metody tej klasy (wtedy będą definiowane raz, a nie w pętli). Funkcji dijkstra_find_path chyba nie trzeba przenosić, bo wywołujesz ją tylko raz, więc nic nie stoi na przeszkodzie żebyś kod który zawiera użył po prostu bezpośrednio w choose_move.

Copy link
Collaborator

@bkrowka bkrowka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Klasa.

@bkrowka bkrowka merged commit 30cd3e6 into dev Aug 14, 2025
1 check passed
@bkrowka bkrowka deleted the issue-25 branch August 14, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants