# A simple motion/sense game.

 4 While pondering the question found here: Applications to Video Games, I thought it might be nice to have a visual model for the way localization proceeds. The following code allows the user to move the robot around the world, sense any of the three colors in that world, and get a visual representation of the robots' belief regarding its position. With a whole lot of imagination I can almost see those homing missiles . . . Also, this program will allow one to experiment with the implications in the order of move(m) and sense(s). Possible now are (m)(m)(m) or (s)(s)(s) or really any other combination. Also, note that one can see the effects upon the probability distribution when one sends a 'wrong' sense result to a well localized robot. I will gladly take suggestions as how to make the code more pythonic! I've only been playing with python since the Stanford AI class . . . So, can you help me improve upon this? Clear explanations for what to replace and why are most helpful! from Tkinter import * import math, sys, tkMessageBox colors = [['blue' , 'blue', 'blue' , 'blue' , 'blue' , 'blue' , 'blue' , ], ['blue' , 'red' , 'green', 'green', 'green', 'red' , 'blue' , ], ['blue' , 'red' , 'red' , 'green', 'red' , 'red' , 'blue' , ], ['blue' , 'red' , 'green', 'red' , 'green', 'red' , 'blue' , ], ['blue' , 'red' , 'green', 'green', 'green', 'red' , 'blue' , ], ['blue' , 'blue', 'blue' , 'blue' , 'blue' , 'blue' , 'blue' , ],] frameWidth = 1000 frameHeight = 500 rows = len(colors) cols = len(colors[0]) initProb = ('%.3f' % (1.0/(rows*cols))) boxWidth = frameWidth / (2 * cols + 4) boxHeight = frameHeight / (rows + 1) if boxHeight

 0 When I first tried to run this code, my IDE gave me an error and told me to install the python-tk package from the Ubuntu repositories. So I did that and now the execution is successful -- however, nothing happens at all. I only get a blank IO window and the ending message stating that the program exited with code 0, which means the interpreter had no runtime problems. Any idea as to what I should do? I'm very impressed and would like to try it out. :) answered 07 Mar '12, 00:01 Lobinho 700●5●8●23 I was in the process of copying and pasting it to a fresh file. The fresh copy and paste worked for me. So, perhaps the root.mainloop() needs to be uncommented? I am using an old debian machine (so we're at least the same flavor OS) and I run the program from IDLE. (07 Mar '12, 00:08) smimic42-1 1 Oh, I hadn't taken a good look into the code before asking that. It's working now. And might I say, you've done a wonderful job! Kudos, mate. "It's really really nice!" (Words that Prof. Thrun seems to love saying. :D ) Btw, do I see a greenish Gmail icon in the known world map? LOL (07 Mar '12, 00:11) Lobinho :-) It was supposed to be my first initial; "M", but I see what you mean. Was it the commented root.mainloop()? (07 Mar '12, 00:24) smimic42-1 Yep. Dude, your program is awesome. I think Prof. Thrun should take a look at it and perhaps use it for demonstration in future iterations of this course. It shows very well how the agent behaves and what it believes about its location in the world, given a map. Again, congratulations. :) (07 Mar '12, 00:28) Lobinho
 0 Known issues: If the probability goes above 0.94 (or so), the shading behaves oddly. I suspect it has something to do with: bg = '#'+hex(int(4095*(1.00 - float(p[i][j]))))[2:]*3,  I altered the probability in buildPRow() to make it display nicely. These nicely displayed numbers are then used as the actual probability later. This causes small probabilities to be lost. I think if the format alteration were made in robotMap() instead of in buildPRow() I could avoid this. A cycling of motions without sensing should eventually completely smooth the probability distribution. It does not. I think the problem may be related to #2 above. answered 07 Mar '12, 11:02 smimic42-1 220●3●14 Issue #2 & #3 can both be fixed by changing the 'text' line in robotMap() to: text = str('%.3f' % float(p[i][j])),  and removing the formatting in buildPRow() like so: row.append(q[count])  (07 Mar '12, 11:15) smimic42-1 Issue #1 resolved in robotMap() as follows: bg = '#'+hex(int(4095*(1.00 - float(p[i][j]))))[2:].zfill(3)*3,  (07 Mar '12, 12:14) smimic42-1
 0 You can also take a look at this, an in-browser implementation that will use your python code answered 07 Mar '12, 11:06 Anna-Chiara ... 5.2k●10●31●75 1 Nice! I really like the fact that the robot can have move and sense failures. (07 Mar '12, 11:31) smimic42-1 thank you! (07 Mar '12, 11:33) Anna-Chiara ...
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×5,185
×323
×76
×24
×7
×2