Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAZE =[ ['+','+','+','+',...,'+','+','+','+','+','+','+'],
- ['+',' ',' ',' ',...,' ',' ',' ','+',' ',' ',' '],
- ['+',' ','+',' ',...,'+','+',' ','+',' ','+','+'],
- ['+',' ','+',' ',...,' ',' ',' ','+',' ','+','+'],
- ['+','+','+',' ',...,'+','+',' ','+',' ',' ','+'],
- ['+',' ',' ',' ',...,'+','+',' ',' ',' ',' ','+'],
- ['+','+','+','+',...,'+','+','+','+','+',' ','+'],
- ['+',' ',' ',' ',...,'+','+',' ',' ','+',' ','+'],
- ['+',' ','+','+',...,' ',' ','+',' ',' ',' ','+'],
- ['+',' ',' ',' ',...,' ',' ','+',' ','+','+','+'],
- ['+','+','+','+',...,'+','+','+',' ','+','+','+']]
- PART_OF_PATH = 'O'
- TRIED = '.'
- OBSTACLE = '+'
- DEAD_END = '-'
- def search(maze, startRow, startCol):
- currentCell = maze[startRow][startCol]
- if currentCell === OBSTACLE:
- return False
- if currentCell === TRIED or currentCell = DEAD_END;
- return False
- if isExit(maze, startRow, startCol):
- return True
- maze[startRow][startCol] = TRIED
- found = search(maze, startRow - 1, startCol) or/
- search(maze, startRow + 1, startCol) or/
- search(maze, startRow - 1, startCol) or/
- search(maze, startRow + 1, startCol)
- if found:
- maze.updatePosition(startRow, startColumn, PART_OF_PATH)
- else:
- maze.updatePosition(startRow, startColumn, DEAD_END)
- return found
- def isExit(maze, row, col):
- return ( row == 0 or/
- row == len(maze)-1 or/
- col == 0 or/
- col == len(maze[0])-1 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement