Пример #1
0
 def test01a(self):
     """ no target => exploration """
     ant = AntFemale(self.grid, NO_SPRITE, None, randomizer=DeterministRandomizer())
     self.grid.put(2, 2, ant)
     self.grid.diffuse()
     ant.prepareToMove()
     self.assertEquals("exploration", str(ant.state))
Пример #2
0
 def test04(self):
     """ ant movement in exploration """
     ant = AntFemale(self.grid, NO_SPRITE, None, randomizer=DeterministRandomizer())
     self.grid.put(2, 2, ant)
     self.grid.diffuse()
     ant.prepareToMove()
     self.assertEquals("exploration", str(ant.state))
     ant.move()
     self.assertNotEquals((2, 2), (ant.x, ant.y))
Пример #3
0
 def test03(self):
     """ target reached => staying there """
     ant = AntFemale(self.grid, NO_SPRITE, None, randomizer=DeterministRandomizer())
     target = AntFemaleTarget(self.grid, NO_SPRITE)
     self.grid.put(2, 2, ant)
     self.grid.put(2, 2, target)
     ant.goToTarget(target)
     ant.prepareToMove()
     self.assertEquals("foundTarget", str(ant.state))
Пример #4
0
 def test01b(self):
     """ target not detected => exploration """
     ant = AntFemale(self.grid, NO_SPRITE, None, randomizer=DeterministRandomizer())
     target = AntFemaleTarget(self.grid, NO_SPRITE)
     self.grid.put(2, 2, ant)
     self.grid.put(0, 0, target)
     ant.goToTarget(target)
     self.grid.diffuse()
     ant.prepareToMove()
     self.assertEquals("exploration", str(ant.state))
Пример #5
0
 def test02(self):
     """ target detected => following the scent """
     ant = AntFemale(self.grid, NO_SPRITE, None, randomizer=DeterministRandomizer())
     target = AntFemaleTarget(self.grid, NO_SPRITE)
     self.grid.put(2, 2, ant)
     self.grid.put(0, 0, target)
     ant.goToTarget(target)
     self.grid.diffuse()
     self.grid.diffuse()
     ant.prepareToMove()
     self.assertEquals("following target", str(ant.state))
Пример #6
0
 def test06(self):
     """ ant movement when target reached """
     ant = AntFemale(self.grid, NO_SPRITE, None, randomizer=DeterministRandomizer())
     target = AntFemaleTarget(self.grid, NO_SPRITE)
     self.grid.put(2, 2, ant)
     self.grid.put(2, 2, target)
     ant.goToTarget(target)
     self.grid.diffuse()
     self.grid.diffuse()
     ant.prepareToMove()
     self.assertEquals("foundTarget", str(ant.state))
     ant.move()
     self.assertEquals((2, 2), (ant.x, ant.y))
Пример #7
0
 def test08(self):
     """ a female that reaches its target on soil becomes a queen """
     def promote(life):
         return AntQueen(self.grid, NO_SPRITE, life=life)
     ant = AntFemale(self.grid, NO_SPRITE, promote, life=3, randomizer=DeterministRandomizer())
     target = AntFemaleTarget(self.grid, NO_SPRITE)
     self.grid.put(2, 2, Soil(self.grid))
     self.grid.put(2, 2, ant)
     self.grid.put(2, 2, target)
     ant.goToTarget(target)
     self.grid.diffuse()
     self.grid.diffuse()
     ant.prepareToMove()
     self.assertEquals("foundTarget", str(ant.state))
     queen = ant.move()
     self.assertNotEquals(ant, queen)
     self.assertTrue(self.grid.has(2, 2, queen))
     self.assertEquals((2, 2), (queen.x, queen.y))
     self.assertEquals(AntQueen, queen.__class__)
     self.assertEquals(ant._life, queen._life)
Пример #8
0
 def test07(self):
     """ ants die """
     ant = AntFemale(self.grid, NO_SPRITE, None, life=3, randomizer=DeterministRandomizer())
     target = AntFemaleTarget(self.grid, NO_SPRITE)
     self.grid.put(2, 2, ant)
     self.grid.put(2, 2, target)
     ant.goToTarget(target)
     self.grid.diffuse()
     self.grid.diffuse()
     ant.prepareToMove()
     ant.move()
     self.assertFalse(ant.isDead())
     ant.prepareToMove()
     ant.move()
     self.assertFalse(ant.isDead())
     ant.prepareToMove()
     ant.move()
     self.assertTrue(ant.isDead())
     self.assertEquals((None, None), (ant.x, ant.y))
Пример #9
0
 def test05(self):
     """ ant movement in target follow """
     ant = AntFemale(self.grid, NO_SPRITE, None, randomizer=DeterministRandomizer())
     target = AntFemaleTarget(self.grid, NO_SPRITE)
     self.grid.put(2, 2, ant)
     self.grid.put(0, 0, target)
     ant.goToTarget(target)
     self.grid.diffuse()
     self.grid.diffuse()
     ant.prepareToMove()
     self.assertEquals("following target", str(ant.state))
     ant.move()
     self.assertEquals((1, 1), (ant.x, ant.y))
     ant.prepareToMove()
     ant.move()
     self.assertEquals((0, 0), (ant.x, ant.y))