badbear1727 / rur-ple

Automatically exported from code.google.com/p/rur-ple
GNU General Public License v2.0
0 stars 0 forks source link

Using "r=UsedRobot(); r.move()" after removing default robot triggers multiple problems. #37

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run rur, switch to "Robot: Code and Learn", create following program
r = UsedRobot(5, 5)
r.move()
r.turn_off()
2. Resize world to 8x8 (world is resized incorrectly, but this is not error we 
are focusing on now, so switch to RuR: Read and Learn and switch back to Robot: 
Code and Learn to repaint world correctly).
3. Click Remove/add robot button, no robots are visible in the world, world 
size is 8x8.
4. Run program.

What is the expected output? What do you see instead?

Expected is: My new robot is the only one in the world. It moves one step in 
the middle of the world and shuts itself down. World should be 8x8. Everything 
should be painted correctly.

Isntead we get: Exception on r.move(), world size changed to 10x10, but world 
is painted with errors (right and bottom edge is of size 8x8, but left and 
upper edge is of size 10x10). There are two robots visible in the world, one in 
the left lower corner (rendered only partially), one in the middle of the world.

What version of the product are you using? On what operating system?

URL: http://rur-ple.googlecode.com/svn/trunk
Repository Root: http://rur-ple.googlecode.com/svn
Repository UUID: 45ae81e0-0e48-11de-98bb-07cc9828235c
Revision: 108

Python 2.6.6
python-wxgtk2.8
Linux version 2.6.32-5-amd64 (Debian 2.6.32-31)

Please provide any additional information below.

Seems that Singleton is broken. __init__() for Visible_world and World is 
called each time addNewRobot() is called by constructor of UsedRobot. This 
leads to reset of some variables (e.g. robot_number, avenues and streets) which 
leads to world size change and possibly giving unnamed robot a name which 
consists of robot and multiple digits 1 after it (robot1, robot11, robot111, 
instead of robot1, robot2, robot3). Additionally somehow the dict with robots 
is refilled with old contents at this time, even if you have clicked Remove/add 
robots and there were no robots in dict. More interestingly, as soon as 
addNewRobot returns, dict with robots is again empty!!! I don't understand 
fully what is going on, but following workaround seems to remove problem.

--- rur_py/world_creation.py    (revision 108)
+++ rur_py/world_creation.py    (working copy)
@@ -80,6 +80,9 @@
     beepers_dict = {}
     def __init__(self, avenues=10, streets=10, walls = [], beepers = {},
                   robot = {}):
+        if hasattr(self, 'initialized') : return
+        self.initialized = 1
         self.av = avenues
         self.st = streets
         self.robot_dict = robot
@@ -234,7 +245,11 @@
                 beeper_number_colour = "black"
                 ):

+
+        if hasattr(self, 'initialized') : return
         World.__init__(self, avenues, streets, walls, beepers, robot)
+        self.initialized = 1

         settings = conf.getSettings()

I was not trying to check if guard in only World or only in Visible_world would 
be sufficient, because it is just ad hoc workaround for broken Singleton, and 
not a real cure to the problem. Why the singleton at all? Would not using just 
global object in module be sufficient?

Original issue reported on code.google.com by razu...@gmail.com on 28 May 2011 at 5:23