Exemplo n.º 1
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))
Exemplo n.º 2
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))
Exemplo n.º 3
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))
Exemplo n.º 4
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)
Exemplo n.º 5
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))