From e4a0f19301959080939790264dbad5efd27ff4de Mon Sep 17 00:00:00 2001 From: Aniela Walczak Date: Sat, 2 Apr 2022 14:05:51 +0200 Subject: [PATCH] Zaktualizuj 'agent.py' --- agent.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/agent.py b/agent.py index bb90851..df6ce6b 100644 --- a/agent.py +++ b/agent.py @@ -123,3 +123,18 @@ class Agent: def idzWPrawo(self): self.poleStartoweGorne.kolumna += 1 + + def bfs(graph, start, cel): + sciezka = [start] + wierzcholek_sciezka = [start, sciezka] + bfs_kolejka = [wierzcholek_sciezka] + odwiedzone = set() + while bfs_kolejka: + aktualne, sciezka = bfs_kolejka.pop(0) + odwiedzone.add(aktualne) + for neighbor in graph[aktualne]: + if neighbor not in odwiedzone: + if neighbor is cel: + return sciezka + [neighbor] + else: + bfs_kolejka.append([neighbor, sciezka + [neighbor]])