Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

pelikan

  • 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
  1. rsmith6559
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  2. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what problem are you having?

  3. MicroBot
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    line 263 also should be += not =+...i agree with rsmith. and yes please be more specific on problems it gives you.

  4. MicroBot
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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?

  5. pelikan
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  6. pelikan
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  7. MicroBot
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    on your corrected code ...still line 263: numSteps =+ 1 must be numSteps += 1

  8. pelikan
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    OK here it is again: http://dpaste.com/hold/847230/. Thanks

  9. MicroBot
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

  10. MicroBot
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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?

  11. pelikan
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  12. MicroBot
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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).

  13. MicroBot
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

  14. pelikan
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  15. MicroBot
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    good luck mate:)

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

    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.