anonymous
  • anonymous
Hi can anyone help me with PS11 (2008 course) problem 3? It's the "runSimulation" problem. I've started from scratch several times and I keep coming up against the same problem. Any help or advice would be greatly appreciated. Here is my code http://dpaste.com/hold/847230/ . Thanks
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
rsmith6559
  • rsmith6559
Very quick read: Line 269, the operator should be += not =+. This problem should be handled in several small functions, not one big one. In another course it was mentioned that a function should ideally be less than 15 lines of code.
anonymous
  • anonymous
what problem are you having?
MicroBot
  • MicroBot
line 263 also should be += not =+...i agree with rsmith. and yes please be more specific on problems it gives you.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

MicroBot
  • MicroBot
visualize: a boolean (True to turn on visualization)....u didnt add any visualization on purpose because u didnt get the results or u forgot about it?
anonymous
  • anonymous
Thanks for correcting that mistake. The problem comes from the "runSimulation" function. In this function I generate a random position; p = B.getRandomPosition(). Then I try to update the position by calling another function; p = D.updatePositionAndClean(). Inside the update position function I call another function from the "position class"; newPosX = p.getNewPosition(direction, speed).getX() newPosY = p.getNewPosition(direction, speed).getY() where "p" is the initial position. The problem is that the update position function does not recognize the initial position, "p". (Maybe because they are from different classes or because they are inside different functions). I'm not sure how to get the update function to recognise the initial position. Here is the code with the above correction made: http://dpaste.com/hold/847186/ Thanks!
anonymous
  • anonymous
Yes I have put visualize to False initially because that's what is says to do in the problem. I think the next step will be to turn in to True but first I need to get the other part of the code working. Thanks!
MicroBot
  • MicroBot
on your corrected code ...still line 263: numSteps =+ 1 must be numSteps += 1
anonymous
  • anonymous
OK here it is again: http://dpaste.com/hold/847230/. Thanks
MicroBot
  • MicroBot
now.... def getRandomPosition(self): """ Return a random position inside the room. returns: a Position object. """ this method does not set your robot on a random start position ...it just returns a random position in the room. 2nd... your start position should be automatically created when u create a robot for your simulation. 3rd... " The simulation is run with NUM_ROBOTS robots of type ROBOT_TYPE, each with speed SPEED, in a room of dimensions WIDTH x HEIGHT." hope those hints help a bit.
MicroBot
  • MicroBot
im not sure but i think that your updatePositionAndClean of Robot class is wrong.where do you change direction if your next position would be outside of the room?
anonymous
  • anonymous
So inside the "runSimulation" function what if I did something like: p = C.setRobotPosition(B.getRandomPosition()). ? But then the update function still wouldn't recognise "p" as the initial position. I.e. newPosX = p.getNewPosition(direction, speed).getX() ... would still raise an error. I'm having difficulty with the concept of classes, how they work and what they are for. I need to know how the inital position "p" can be recognized inside the update function. Regarding the changing of direction ... Yes I know I need to include some code for that. Thanks
MicroBot
  • MicroBot
well u dont need to set an initial position there...as i told you ...when u create a robot it automaticaly creates one for it (or should).
MicroBot
  • MicroBot
def __init__(self, room, speed): """ Initializes a Robot with the given speed in the specified room. The robot initially has a random direction d and a random position p in the room. The direction d is an integer satisfying 0 <= d < 360; it specifies an angle in degrees. p is a Position object giving the robot's position. room: a RectangularRoom object. speed: a float (speed > 0) """ always read carefully the docs! it says : "The robot initially has a random direction d and a random position p in the room." so you have to initialize its position and direction in the __init__ method. it will not "fix" your pset but its a start!:) gl !feel free to contact me any further.
anonymous
  • anonymous
OK thanks. I get the feeling I have not understood some quite important aspects of object oriented programming. I'm going to look for some reading material on it and I'll have another go once I have read it. Thanks
MicroBot
  • MicroBot
good luck mate:)

Looking for something else?

Not the answer you are looking for? Search for more explanations.