[GRASS-SVN] r54798 - grass-addons/grass7/raster/r.agent/libagent

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 27 15:13:52 PST 2013


Author: mic
Date: 2013-01-27 15:13:52 -0800 (Sun, 27 Jan 2013)
New Revision: 54798

Modified:
   grass-addons/grass7/raster/r.agent/libagent/playground.py
   grass-addons/grass7/raster/r.agent/libagent/world.py
Log:
implement bear and random position

Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-01-27 21:36:59 UTC (rev 54797)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-01-27 23:13:52 UTC (rev 54798)
@@ -9,7 +9,7 @@
               for details.
 """
 
-import numpy, error
+import numpy, error, random
 
 class Playground(object):
     """
@@ -98,3 +98,11 @@
         #TODO overwrite policy: to increment or to fail?
         pass
 
+    def getrandomposition(self):
+        """
+        Return a random position on the playground
+        @return list some coordinates
+        """
+        ns = random.randrange(0,self.region["rows"])
+        nw = random.randrange(0,self.region["cols"])
+        return [ns,nw]

Modified: grass-addons/grass7/raster/r.agent/libagent/world.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/world.py	2013-01-27 21:36:59 UTC (rev 54797)
+++ grass-addons/grass7/raster/r.agent/libagent/world.py	2013-01-27 23:13:52 UTC (rev 54798)
@@ -56,15 +56,18 @@
         """
         return self.playground.getlayer(layername)
 
-    def bear(self, timetolive, position, agenttype=None):
+    def bear(self, timetolive, position=None, agenttype=None):
         """
         Set a new agent into the world
         @param int number of cycles the agent has to live
-        @param list coordinates where to put the new agent
+        @param list coordinates to put the agent or none for a random position
         @return agent the newly created agent
         """
-        pass
-#       return agent
+        if not position:
+            position = self.playground.getrandomposition()
+        agent = self.agenttype(timetolive, self, position)
+        self.agents.append(agent)
+        return agent
 
     def getnextagent():
         """



More information about the grass-commit mailing list