Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q6 - WanderBot (1.25 points) Create a class called WanderBot. WanderBot is a bot that will wander around randomly. Instance Attibutes: character string position

imageimageimage

Q6 - WanderBot (1.25 points) Create a class called WanderBot. WanderBot is a bot that will wander around randomly. Instance Attibutes: character string position - list of [int, int] moves list of list of [int, int] grid_size None or int Of these instance attributes, only character should be taken in as an input to __init_____, with a default value of 8982. Inside the init_ : self.character should be set as the chr of input character self.position should be set to starting position [0, 0] self.moves should be set as the list of possible moves, which are [[-1, 0], [1, 0], [0, 1], [0, -1]] self.grid_size should be initialized as None Add two methods to WanderBot: Method: wander This method will choose a random move from the possibilities, making sure that move is valid on the current grid. Procedure: Initialize a boolean variable has_new_pos as False Use a while loop, with the condition not has_new_pos Set a variable move as the output of calling random.choice on self.moves Add move to self.position, using add_lists (a function we created earlier), and assign the output to a new variable new_pos Call check_bounds on new_pos, also passing self.grid_size into check_bounds Assign the output of check_bounds to has_new_pos This will lead to exiting the loop when a valid new position has been assigned . Return new_pos Method: move No inputs (other than self) or outputs, just sets self.position to be the output of calling self.wander (). class WanderBot: def __init__(self, character-8982, position, moves, grid_size): self.character chr (character) self.position = [0,0] self.moves = [[-1,0], [1,0], [0,1], [0,-1]] self.grid_size = None def wander (self, manufacturer, model, year, mpg): has_new_pos= False while (not has_new_pos): move = random.choice (self.moves) new_pos= add_lists (move, self.position) has_new_pos=check_bounds (new_pos, self.grid_size) return new_pos def move (self): self.position=self.wander() : class WanderBot: def _init__(self, character-8982, position, moves, grid_size): self.character = chr(character) self.position = [0,0] self.moves [[-1,0], [1,0], [0,1], [0,-1]] self.grid_size = None def wander (self, manufacturer, model, year, mpg): has_new_pos = False while (not has_new_pos): move = random.choice (self.moves) new_pos= add_lists (move, self.position) has_new_pos=check_bounds (new_pos, self.grid_size) return new_pos def move (self): self.position=self.wander() File "/tmp/ipykernel_186/1704160856.py", line 2 def __init__(self, character-8982, position, moves, grid_size): SyntaxError: non-default argument follows default argument : assert WanderBot wbot assert wbot WanderBot () TypeError /tmp/ipykernel_186/27214554.py in 1 assert WanderBot ----> 2 wbot = WanderBot () 3 assert wbot. Traceback (most recent call last)

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_2

Step: 3

blur-text-image_3

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

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions