Neuron 101

Solving by search / BFS

Türkçe

Plate14

Unit 2 · Topic 3 of 10

BFS

Easy, 6 min, 9 steps

S
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 9 Maze

The maze

S is the start and the flag is the goal. Black blocks are walls, brown cells are mud: entering mud costs 3, entering a plain cell costs 1. BFS ignores the mud and only counts steps.

Tap a part of the scene to see its details here.

Open in Colab
  1. from collections import deque
  2. def bfs(harita, S, G):
  3. kuyruk = deque([S])
  4. ebeveyn = {S: None}
  5. while kuyruk:
  6. x = kuyruk.popleft()
  7. if x == G:
  8. break
  9. for k in komsular(harita, x):
  10. if k not in ebeveyn:
  11. ebeveyn[k] = x
  12. kuyruk.append(k)
  13. return ebeveyn
acilan
0
sinir
1
yolUzunlugu
0
maliyet
0