464464 ],
465465]
466466
467- < << << << HEAD
468- def print_maze (maze : list [list [str ]], stdscr : curses .window , visited : set [tuple [int , int ]], path : list [tuple [int , int ]] = []) -> None :
469- == == == =
470467
471468def print_maze (
472469 maze : list [list [str ]],
473470 stdscr : curses .window ,
474471 visited : set [tuple [int , int ]],
475472 path : list [tuple [int , int ]] = [],
476473):
477- > >> >> >> 53 c60ed56655b224ef80b893f97852533b47d130
478474 blue = curses .color_pair (1 )
479475 red = curses .color_pair (2 )
480476 green = curses .color_pair (3 )
@@ -489,7 +485,6 @@ def print_maze(
489485 stdscr .addstr (row , column * 2 , j , blue )
490486
491487
492- < << << << HEAD
493488def find (maze : list [list [str ]], start : str ) -> tuple [int , int ] | None :
494489 """
495490 Find the first occurrence of a given element (like 'O' for start or 'X' for target) in the maze.
@@ -503,23 +498,12 @@ def find(maze: list[list[str]], start: str) -> tuple[int, int] | None:
503498 >>> find(maze, "Z") is None
504499 True
505500 """
506- == == == =
507- def find (
508- maze : list [list [str ]], start : str
509- ) -> tuple [int , int ] | None : # to check and return starting position in maze
510- > >> >> >> 53 c60ed56655b224ef80b893f97852533b47d130
511501 for row , i in enumerate (maze ):
512502 for column , j in enumerate (i ):
513503 if j == start :
514504 return (row , column )
515505 return None
516506
517- < << << << HEAD
518- == == == =
519-
520- def find_neighbours (maze : list [list [str ]], row : int , col : int ) -> list [tuple [int , int ]]:
521- neighbours = []
522- > >> >> >> 53 c60ed56655b224ef80b893f97852533b47d130
523507
524508def find_neighbours (maze : list [list [str ]], row : int , col : int ) -> list [tuple [int , int ]]:
525509 """
@@ -546,7 +530,6 @@ def find_neighbours(maze: list[list[str]], row: int, col: int) -> list[tuple[int
546530 return neighbours
547531
548532
549- < << << << HEAD
550533def traverse (maze : list [list [str ]], stdscr ) -> list [tuple [int , int ]] | None :
551534 """
552535 Run a breadth-first search on the maze and return the path from start 'O' to target 'X'.
@@ -565,11 +548,6 @@ def traverse(maze: list[list[str]], stdscr) -> list[tuple[int, int]] | None:
565548 >>> path == expected_path
566549 True
567550 """
568- == == == =
569- def traverse (
570- maze : list [list [str ]], stdscr : curses .window
571- ) -> list [tuple [int , int ]] | None : # implementing bfs traversal
572- > >> >> >> 53 c60ed56655b224ef80b893f97852533b47d130
573551 start = "O"
574552 target = "X"
575553 start_pos = find (maze , start )
0 commit comments