Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

What is the significance of digitalization?

Answered: 1 week ago

Question

Which shape is defined by the equation (y+4) = 1? 81 x2 16

Answered: 1 week ago