A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 2 years ago
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
 2 years ago
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

This Question is Open

rsmith6559
 2 years ago
Best ResponseYou've already chosen the best response.0Very 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.

bwCA
 2 years ago
Best ResponseYou've already chosen the best response.0what problem are you having?

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.1line 263 also should be += not =+...i agree with rsmith. and yes please be more specific on problems it gives you.

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.1visualize: 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?

pelikan
 2 years ago
Best ResponseYou've already chosen the best response.0Thanks 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!

pelikan
 2 years ago
Best ResponseYou've already chosen the best response.0Yes 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
 2 years ago
Best ResponseYou've already chosen the best response.1on your corrected code ...still line 263: numSteps =+ 1 must be numSteps += 1

pelikan
 2 years ago
Best ResponseYou've already chosen the best response.0OK here it is again: http://dpaste.com/hold/847230/. Thanks

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.1now.... 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
 2 years ago
Best ResponseYou've already chosen the best response.1im 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?

pelikan
 2 years ago
Best ResponseYou've already chosen the best response.0So 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
 2 years ago
Best ResponseYou've already chosen the best response.1well 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
 2 years ago
Best ResponseYou've already chosen the best response.1def __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.

pelikan
 one year ago
Best ResponseYou've already chosen the best response.0OK 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
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.