these two task are all about \"maze\" exploring.. i have done the first three pa
ID: 3641347 • Letter: T
Question
these two task are all about "maze" exploring..i have done the first three parts those where about load maze, Getting an Adjacent Position and Make a Move.
but caouldnt go anyfurther with these two tasks:
2.2.4 Where can I go
get_legal_directions(maze, position) takes, as arguments, the maze
(as a list of lists) and a position of a square and returns a list of legal directions
for that square. You may assume the given position is legal.
For example:
>>> maze = load_maze('maze1.txt')
>>> get_legal_directions(maze, (2,1))
['N', 'S']
>>> get_legal_directions(maze, (3,1))
['N', 'E']
>>>
2.2.5 Check the Command
is_valid_command(command) takes a string of length one and returns True
if and only if the given command is one of the allowed commands. For
example:
>>> is_valid_command('A')
False
>>> is_valid_command('?')
True
>>>
Explanation / Answer
########## def search(x, y): if grid[x][y] == 2: print 'found at %d,%d' % (x, y) return True elif grid[x][y] == 1: print 'wall at %d,%d' % (x, y) return False elif grid[x][y] == 3: print 'visited at %d,%d' % (x, y) return False print 'visiting %d,%d' % (x, y) grid[x][y] = 3 if ((x 0 and search(x, y-1))or (x > 0 and search(x-1, y))or (yRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.