Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 25 Online
OpenStudy (anonymous):

Hi Im back again. Im working on ps11 #4. Im confident that my problem is in my baseRobot class more specifically my isPositionInRoom function under rectangularRoom. can anyone help me debug this? isPostionInRoom isn't returning true when it should and is causing me to go infinite loop on line 244. Here's my code thus far: http://dpaste.com/hold/584037/

OpenStudy (anonymous):

in your RectangularRoom class, the method isPositionInRoom is a function of whether a tile is clean or not. Instead, it should be a function of whether pos is within the rectangular room boundaries. Also, I think pos are floats and are not necessarily integer tile coordinates, which affects your cleanTileAtPosition method.

OpenStudy (anonymous):

ok so i think i sort of get what your saying.... I did this to combat the isPositionInRoom problem and the pos problem. However, my room doesn't get clean.... and it takes forever. I'm thinking that it's my while loop on line 256.... Any suggestions on how to combat this?

OpenStudy (anonymous):

In your updatePositionAndClean method you call genNewPosition in the while loop. In isPositionInRoom, you have the input position defined as integer pair (m,n). But getNewPosition returns position as float pair (x,y) which is unlikely to be an integer pair and thus not in the room. I think the program intent is for position to be a float pair (x,y). In cleanTileAtPosition, you probably want to take the (x,y) float pair and quantize it to a (m,n) tile.

OpenStudy (anonymous):

sorry I forgot to post my updated code: http://dpaste.com/hold/585061/

OpenStudy (anonymous):

I think your problem is still in the while loop. getNewPosition moves the robot to a new location based on the current location, direction, and speed. If the robot goes outside the room, you randomly change the direction, but this could move the robot further from the room, and since it is random, there is a chance the robot won't find it's way back to the room (and exit the while loop).

OpenStudy (anonymous):

yeah I noticed that and also found another primary bug. thanks anyway and heres what I have for #4: http://dpaste.com/hold/586361/ Now im trying to get the whole pylab thing :O

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!