[GRASS-SVN] r54763 - grass-addons/grass7/raster/r.agent/libagent
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 23 15:18:32 PST 2013
Author: mic
Date: 2013-01-23 15:18:31 -0800 (Wed, 23 Jan 2013)
New Revision: 54763
Modified:
grass-addons/grass7/raster/r.agent/libagent/agent.py
grass-addons/grass7/raster/r.agent/libagent/ant.py
Log:
add docstring comments
Modified: grass-addons/grass7/raster/r.agent/libagent/agent.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/agent.py 2013-01-23 17:06:43 UTC (rev 54762)
+++ grass-addons/grass7/raster/r.agent/libagent/agent.py 2013-01-23 23:18:31 UTC (rev 54763)
@@ -10,30 +10,62 @@
"""
class Agent(object):
- """Generic Agent class with limited capabilities, as a basis for
- child classes."""
+ """
+ Generic Agent class with limited capabilities, as a basis for
+ child classes.
+ """
+
def __init__(self, timetolive, world, position=[]):
+ """
+ Create an Agent, an actor on playgrounds, living in a world
+ @param int time to live
+ @param World the agent knows the worlds he lives in
+ @param list coordinate of the current position
+ """
self.ttl = timetolive
self.world = world
self.position = position
self.knowscompass = False
self.freedom = 0
+
def setposition(self, position):
+ """
+ Move the agent to a certain position
+ @param list coordinate of the current position
+ """
if position and position != []:
self.position[0] = position[0]
self.position[1] = position[1]
+
def getposition(self):
+ """
+ Ask the agent for its current position
+ @return list coordinate of the current position
+ """
return self.position
+
def move(self, nrofsteps, direction):
- pass
+ """
+ Let the agent move
+ @param int the number of steps to walk
+ @param char the direction to go
+ @return list coordinate of the current position
+ """
+ return self.position
+
def age(self):
+ """
+ Let the agent grow older
+ @return boolean whether agent is still alive
+ """
if self.ttl > 0:
self.ttl -= 1
return True
else:
self.snuffit()
return False
+
def snuffit(self):
- """to die peacefully and without pain."""
+ """to die peacefully and without pain"""
self.world.kill(self)
Modified: grass-addons/grass7/raster/r.agent/libagent/ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-01-23 17:06:43 UTC (rev 54762)
+++ grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-01-23 23:18:31 UTC (rev 54763)
@@ -8,13 +8,21 @@
License (>=v2). Read the file COPYING that comes with GRASS
for details.
"""
+
from random import choice, randint
import agent
import error
class Ant(agent.Agent):
"""Implementation of an Ant Agent for an ACO kind of World."""
+
def __init__(self, timetolive, world, position):
+ """
+ Create an Agent for an ACO World
+ @param int time to live
+ @param World the agent knows the worlds he lives in
+ @param list coordinate of the current position
+ """
agent.Agent.__init__(self, timetolive, world, position)
self.position.extend([None,None,0,0])
self.home = self.position[:]
@@ -25,4 +33,3 @@
self.goal = []
self.penalty = 0.0
-
More information about the grass-commit
mailing list