Question: Python programming language required A beast is in a labyrinth, which is represented as a rectangular grid. At any moment, the beast is at one

Python programming language required

Python programming language required A beast is in a labyrinth, which isrepresented as a rectangular grid. At any moment, the beast is atone particular position and is turned in one of four possible directions(up, down, left and right). In each round the beast makes onemove: it will either turn left, turn right or take one step

A beast is in a labyrinth, which is represented as a rectangular grid. At any moment, the beast is at one particular position and is turned in one of four possible directions (up, down, left and right). In each round the beast makes one move: it will either turn left, turn right or take one step forward. At the beginning, the beast will always have a wall to its right. As the beast moves it tries to follow this wall at all times (see the sample output below). Standard input will contain an integer N on its own line, followed by a map of the labyrinth. Individual characters depict individual positions: 'x' is a wall and'.' is an empty spot. The characters '', '>', 'v' and 'X XXXXX XXXXX X...X X..^x XXXXX XXXXX X..^X X... XXXXX XXXXX X.... .... ...... XXXXXXXXXX XXXXXXXXXX ...... ... .3. .... X,X..... XXXXXXXXXX ....... x......> .... ...... ... .... x, .... v .... ...... XXXXXXXXXX ,...... ....... ...v ..... XXXXXXXXXX X....X... X....X...X X.X.X.X.X X.X....XvX XXXXXXXXXX XXXXXXXXXX X....X...X X....X...X X.X.X.X.X X.X....XXX XXXXXXXXXX XXXXXXXXXX X....X...X X....X...X X.X.X.X.X X.X....X^X XXXXXXXXXX XXXXXXXXXX X....X...X X. ...X... X.X.X.X^X X.X....X.X XXXXXXXXXX XXXXXXXXXX X....X...X X....X..^x X.X..X.X.X X.X....X.X XXXXXXXXXX Sample input #3: 3 XXXXXXXXXXXX X. ......... X.........^X XXXXXXXXXXXX Output: XXXXXXXXXXXX X.........^X X..... XXXXXXXXXXXX XXXXXXXXXXXX X.........''X XXXXXXX XXXXXXX X.X.X.X X.X.X.X X.<...x xxxxxxx x.x.x.x x x.....x hints: use input to read n then sys.stdin the maze. here is some pseudocode that explains how beast behaves: while true: if there an open space right: turn right walk forward else ahead: else: left you store maze as a list of strings can access each character however note are immutable. want be able modify characters in could convert row using function. back string join method will helpful. try avoid writing code repeated four times once for compass direction. it might helpful write classes pos and vec represent position vector these orientation. even magic __add__that lets add position. rotate dy degrees get dx i am assuming y-coordinates increase move downward which usual convention computer graphics.>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!