[GRASS-SVN] r66830 - in grass-addons/grass7/raster/r.agent: libagent tests
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Nov 14 16:56:10 PST 2015
Author: mic
Date: 2015-11-14 16:56:10 -0800 (Sat, 14 Nov 2015)
New Revision: 66830
Modified:
grass-addons/grass7/raster/r.agent/libagent/ant.py
grass-addons/grass7/raster/r.agent/tests/test_ant.py
Log:
Fix off by one and empty array
Modified: grass-addons/grass7/raster/r.agent/libagent/ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/ant.py 2015-11-15 00:24:22 UTC (rev 66829)
+++ grass-addons/grass7/raster/r.agent/libagent/ant.py 2015-11-15 00:56:10 UTC (rev 66830)
@@ -176,14 +176,14 @@
"""
self.position = self.nextstep
if len(self.laststeps) > 1:
- # walk only up to the gates of the hometown
- self.nextstep = self.laststeps.pop()
# try to avoid loops
if (self.world.antavoidsloops):
# Find the first occurence of this step in the path array
- i = self.laststeps.index(self.nextstep)
+ i = self.laststeps.index(self.laststeps[-1])
# Forget the path (the loop) inbetween
- self.laststeps = self.laststeps[0:i]
+ self.laststeps = self.laststeps[0:i+1]
+ # walk only up to the gates of the hometown
+ self.nextstep = self.laststeps.pop()
self.penalty += self.nextstep[3] + \
self.world.getpenalty(self.nextstep)
else:
Modified: grass-addons/grass7/raster/r.agent/tests/test_ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_ant.py 2015-11-15 00:24:22 UTC (rev 66829)
+++ grass-addons/grass7/raster/r.agent/tests/test_ant.py 2015-11-15 00:56:10 UTC (rev 66830)
@@ -108,6 +108,10 @@
self.agent.walkhome()
expected = []
self.assertEqual(expected, self.agent.laststeps)
+ self.agent.laststeps = [[1,1,0,0], [0,1,0,0], [0,0,0,0]]
+ self.agent.walkhome()
+ expected = [[1,1,0,0], [0,1,0,0]]
+ self.assertEqual(expected, self.agent.laststeps)
def test_walkaround(self):
self.agent.position = [0,0]
More information about the grass-commit
mailing list