Good evening. I would need a fresh set of eyes on my code if anyone has time. I have written a code for PSET 11, even checked a code on github and mine looks almost the same as that one. However, something is wrong. The simulation part is not working for some reason. The code gets stuck in a loop. It seems ok for me, can't find the problem. If you just hit F5 you will see where the problem is in the loop. Thank you
The problem is somewhere in the function, which starts at line 223. Made tests on other functions and they seem to work.
I don't see where height, width and speed are getting their initial values in that function. It's also a fairly complicated prototype that could be called with a couple of parameters transposed. Print statements of the values of all the values in the function before the loop could be very interesting.
You seem to have an issue here, at least it appears to enter an infinite loop, while coverage < min_coverage: # Line 255 coverage seems to always be 0.04 when this condition is evaluated. After 263 iterations, the value is a constant 0.04. I have not looked into the logic for this as it would take more time than I have, suffice it to say that you know your code and should look here and see why this value isn't changing.
did you turn the animation on? - is/are the bot(s) moving and cleaning?
http://dpaste.com/1289364/ i added a __str__() method to Position at line 48 and another print statement to runSimulation at line 260. i see two things in the printouts: - the robot goes to negative coordinates and gets stuck there - the robot's direction never changes http://dpaste.com/1289391/
I knew that the problem is with coverage, but negatives numbers?? Would have never suspected them, will check. Thank you.
By the way, I did not turn on the animation, as I was not supposed to at the moment.
Moreover, I have created a testRobot, and used the updatePosAndClean function. It moves the robot to another tile and cleans at its location. The could kind of should work, but just need to find why I get negative values all of a sudden. The robot shouldn't walk out of the field. There is an IF statement in the updatePosAndClean to prevent this.
the updateAndClean() says that if the new position is valid (inside the room), do the following: clean the tile and set it as the new position. If not - generate a new direction at random. But it doesn't do that for some reason.
debuged, just rewrote the rectangularRoom class in another way. Don't really know what was the problem.
My program cleaned already clean tiles and added them as separate tiles. This lead to, that at each move the robot cleaned something. Therefore, the percentage of clean room was the same as the size of the whole room. Note to self and others: do not peek at others code before you finish yourself. This lead me to this confusion, because I though the code I found on the web was true (which wasn't).
Mind pasting your newest version? a couple of tips (line #'s refer to http://dpaste.com/1289364/): if an expression evalutes to a boolean, use it instead of comparing it to True or False - line 212 should be; while notAtWall: ..... - line 215 should be ; if self.room.isPositionInRoom(newPos): ..... http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#testing-for-truth-values True and False evaluate to 1 and 0 - if you have a sequence/iterable of True/False values and you want to accumulate all the True items you can use; sum(iterable) - lines 112-114 could be sum(self.tileDic.values()) try this in a python shell - sum([True, True, False, False, True, False]) line 218 might be better expressed with a return statement. at that point, you are done and really don't want or need to continue to the top of the while loop so just return - when I read yours, i had to figure out what that was doing, a simple return would have been clear and succinct
Thank you for the tips. I will try to use them. Thank you for your time!
This code work fine now, but it is not entirely mine, did some cheating (out of desperation)
hmm ... looks like iterable.count(True) is much faster than sum(iterable): http://dpaste.com/1290732/
Join our real-time social learning platform and learn together with your friends!