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.
does it work? what problem(s) are you having? you should write code that tests each method of your classes - write the tests based on the specification - known inputs and expected results. then you can run the tests to see if things are working. have you had the debugging lecture yet? be sure to test the corner cases. here is the 2008 testing and debugging lecture http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/video-lectures/lecture-11 since you didn't pose a problem i'll point out things i see - but it will be somewhat specific do lines 30-34 work? line 85 doesn't look quite right does isPositionInRoom work? you might have problems with updatePositionAndClean - Robot isn't supposed to implement updatePositionAndClean
Lines 30-34 insert the coordinates from (0,0) to (4,4) into the dict tiles as keys and give it a value of False to indicate "dirty". I've tested it out and it works as expected. line 85 was just a short way for me to count the number of True values in the dict to return the number of clean tiles. I realize now that updatePositionAndClean was not supposed to be implemented after reading the instructions for Problem 2. I'm confused why updatePositionAndClean is a method for robot. Focusing on Problem 2: http://dpaste.com/1366914/ I want to implement the getNewPosition method from Position class, I don't know if I did it the right way. Here's what I was thinking: Robot will be initiated with a random position with "self.position = self.room.getRandomPosition()". Then these random x,y coordinates will be passed to "self.position.getNewPosition(self.direction, self.speed)" to create a new adjacent position. Is this right? My other concern is where will I make use of the "isPositionInRoom" because I can see that the rest of the program will simulate movement.
when is a good time to check and see if you are still in the room? what does StandardRobot's docstring specify? line 85 of your first post does not look right - is that the correct way to access room? lines 30-34 of your first post - looks like they add a single item ( (0,0)) to tiles and set it to False and it does this widthXheight times line 106 of your first post looks incorrect Robot.position is a Position object which 'knows' its own postion. Position.getNewPosition() only has two arguments - speed and direction - you can't pass it anything else. You should write some unit tests to test your class methods and attributes.
I've looked at the three errors you pointed out and tested and debugged them. I think they're ok now. I now tried to test and debug my code for problem 2. Here is the result: http://dpaste.com/1367715/ Instead of getting a value, I'm getting other data (I think it's called location reference?). My idea was to see what the current position of the robot is, apply updatePositionAndClean and then check the position again to see if the new position made sense (or to see if it worked at all). Can you point me in the right direction on how to debug my code?
line 161 - if your room is 4 x 4, is there a tile at (4,4)? if you 'call' a class method or a module function without the parenthesis, the interpreter will return the method/function object itself. when you 'ask' for a robot's position, you get a Position object. you might want to play around with classes in the shell a bit. it doesn't look like your robot is moving http://dpaste.com/1368137/
"line 161 - if your room is 4 x 4, is there a tile at (4,4)?" - I see now that it shouldn't be a tile since the the first tile is 0,0 and not 1,1 So I think I'm getting a better understanding now. In your example, you can call for robby.getRobotDirection and get the angle because the direction is not an object. But when you call for position, you will get the object itself as your answer because robby.getRobotPosition is an object from the Position class. Am I getting it right? I tried to play around with the Position class to get a better understanding of what it does: http://dpaste.com/1368306/ The first thing I tried to do was create a position pos and then getNewPosition with pos.getNewPosition. I don't understand why pos was still the same. If pos is an object of the Position class, why aren't I able to apply the method getNewPosition to it? My conclusion was because getNewPosition returns an object and I guess you can't apply an object upon an object. So I thought of creating a new object NewPos and that seemed to work. Is this the right approach in getting the robot to move? The other thing I realized I could do is pass the object from getNewPosition as a parameter and that worked too. Is that better? (more efficient)
I don't know if it is more efficient but that is the way to do it, unless you need to do something else with it before you pass it to Robot.setRobotPosition() Position.getNewPosition() doesn't change anything, it just returns a Position object. Robot.setRobotPosition() takes a Position object as an argument. The classes have getAAA and setAAA methods because they intend for you to access the object's attributes with them - e.g. it is not intended to access Robot.position directly http://docs.python.org/2.7/tutorial/classes.html#private-variables-and-class-local-references http://docs.python.org/2.7/tutorial/classes.html http://docs.python.org/2.7/reference/datamodel.html#objects-values-and-types
Here is what I came up with for Problem 2: http://dpaste.com/1368871/ Pseudo code: Create new position NewPos if NewPos is in room: Set Position and Clean Room else: choose random direction and recursively call updatePositionAndClean to apply new direction I've tested it and the robot moves, though the new position doesn't seem adjacent to the original position. Am I correctly using getNewPosition? or am I to write my own code to update to an adjacent position?
looks good - does it work? here's mine http://dpaste.com/1368990/
Here's what it looks like when I test the position: http://dpaste.com/1369011/ I'm working on problem 3 now. I can't think of how to iterate and create robots in quantity of num_robots. Here is what I came up with so far: http://dpaste.com/1369071/ It creates a dict, each key is a new robot and the value is an instance of the class. I'm sure this isn't the best way
What is the best way to keep track of the area cleaned? my first thought was to iterate through a while loop: http://dpaste.com/1369140/ However, I don't see this method working because updatePositionAndClean will move the robots to a new position of coordinates (float,float) as opposed to (int,int), making the number of tiles increase. Am I on the right track?
Had to do some debugging to get my code to run: http://dpaste.com/1369478/ Included some output to show what my code is doing. The averages are much too low, satisfying min_coverage in 1 or 2 time steps. I'm missing something simple I think but can't place my finger on it.
when you are trying to decide which type of container to use for your stuff. one thing to consider is how you will be using that stuff - will the container make it easy for you to do the things you need to do to your stuff. peruse the built-in types and their methods while thinking about that. http://docs.python.org/2.7/library/stdtypes.html if a built-in type doesn't do the trick you can always make your own with a class yep when the robots move they end up at messy float positions and the tiles are 'named' as ints. hmmmm ... i THINK this is what the instructions say trial 0 while the room isn't clean tick - move each bot and clean the tile it is on save the number of ticks it took to clean the room in this trial repeat for all the trials calc the average ticks/trial to clean the room sometimes it helps to write xtra functions for discrete parts of the solution. if you give those functions descriptive names, when you glue them together it is easy to read what its doing. something like this - be creative - http://dpaste.com/1369586/
You're right, the instructions said "When a robot’s location is anywhere in a tile, we will consider the entire tile to be cleaned" so the error was in my method cleanTileAtPosition and I updated it to this: http://dpaste.com/1369682/ I've also created helper functions which makes it look cleaner now: http://dpaste.com/1369692/ I've included some output which compares averages suggested by the instructions and the averages my implementation output. My averages were considerably lower. Does this imply I am doing something wrong?
your bot is cleaning the room two to three times 'faster' than suggested for a speed of 1. Think about how your bot goes about its business - can you account for how your bot is so much better than expected?
The only thing that I can think of that makes the robot clean so fast is how I've implemented cleanTileAtPosition: http://dpaste.com/1373255/ But I don't see the error in my logic. What could I be missing? A nudge in the right direction ?
I got it! I ran the visualization and it was showing two robots instead of one! Corrected my function which built the robots: http://dpaste.com/1373369/ the new output is better, but still a bit faster.
when your bot tries to move but hits a wall, does it just change direction and stop or does it change direction then move and clean? some would interpret the last bullet of the Robot motion rules as meaning in one time tick, the bot either moves and cleans or tries to move but instead just changes direction cause it hits a wall
When watching the animation, I've noticed that if the robot passes through the corner of a box, it does not always mark it as cleaned (usually in a small room of 5x5, where the boxes are 'big'). The other thing I've noticed is that it will continue in a straight path and change directions but it doesn't always wait to "bounce" off the wall. It will change directions just shy of the wall. And this usually happens only on the left wall or the bottom wall, but performs as expected and bounces off the top wall and the right wall. Do you think there is any connection between the observances and why the robot cleans a bit faster? Here is my full code if you want to see the animation: http://dpaste.com/1376271/
http://dpaste.com/1377155/ i put some print statements in and commented out the animation run one trial and look at the printout re-read the robot motion rules is there another way to interpret the rule for hitting a wall?
I ran a simulation with your comments: http://dpaste.com/1384245/ Seems like the "tick" only occurs after the tile has been cleaned. Actually, reading through it, I don't see any irregularity in the movement of the robot. What should I be looking for?
you were wondering why your bot cleaned the room so much faster than the metrics given in the instructions. you should see in the printout that when a bot hits a wall it changes direction (sometimes many times) AND cleans a tile in a single tick. You have interpreted the robot motion rules in a way that lets the bot do multiple things in a single tick. There is another way to interpret those rules which would slow it down a bit - ``` the bot tries to move but hits a wall, it changes direction, and stops (for this tick) ```
Cool, I got it now. To correct the robot so that it does one action per tick, I just had to remove the recursive statement from updatePositionAndClean: http://dpaste.com/1386238/ 100 trials of one robot cleaning a 5x5 room completely averaged 155.43, very close to the suggested 150. Time to move on to the next part of the problem set
so ... the instructions did mention that some of the specifications may be a bit ambiguous and that it was up to you to decide the implementation and that you should document those design decision(s) (probably in a docstring). this would be especially useful for you at some future time when you were wonder why the heck you decided to do that and maybe even for someone else using/reading your code and wondering why the heck you did that.
I started working on problem 4 and was able to do Plot 1 fairly easy: http://dpaste.com/1393868/ Having trouble thinking of how to label the axis for Plot 2 though: http://dpaste.com/1393875/ Plot 2 looks jacked up. For one the plot is abnormal but it might be right. It's hard to tell cause the x-axis is not outputting what I expected. I was hoping it would read 20,20 then 25,26 etc etc. Is that possible to do in pylab?