Beispiel #1
0
    def test_ants_should_avoid_existing_search_traces(self):
        ant = Ant(nest=Nest(0, 0), chemicals=Chemicals())
        ant.chemicals.search += 1.0
        ant.chemicals.search[N.x, N.y] = 0.0
        ant.last_direction = N
        ant.search_strategy = SearchWithAvoidance()

        ant.tick()

        self.assertEqual(N, ant.location)
Beispiel #2
0
    def test_ants_can_all_get_home(self):
        chemicals = Chemicals(size=(10, 10))
        nest = Nest(0, 0)

        chemicals.search[0, 0] = 3
        chemicals.search[1, 1] = 2
        chemicals.search[2, 2] = 1

        ant_1 = Ant(nest=nest, chemicals=chemicals)
        ant_1.food = 1
        ant_1.last_direction = NW
        ant_1.location = Location(3, 3)

        for _ in range(3):
            ant_1.tick()
            self.assertIs(return_state, ant_1.strategy)

        self.assertEqual(Location(0, 0), ant_1.location)

        ant_2 = Ant(nest=nest, chemicals=chemicals)
        ant_2.food = 1
        ant_2.last_direction = NW
        ant_2.location = Location(3, 3)

        for _ in range(3):
            ant_1.tick()
            ant_2.tick()
            self.assertIs(return_state, ant_2.strategy)
            self.assertIs(gather_state, ant_1.strategy)

        self.assertEqual(Location(0, 0), ant_2.location)

        ant_3 = Ant(nest=nest, chemicals=chemicals)
        ant_3.food = 1
        ant_3.last_direction = NW
        ant_3.location = Location(3, 3)

        for _ in range(3):
            ant_1.tick()
            ant_2.tick()
            ant_3.tick()

        self.assertEqual(Location(0, 0), ant_3.location)
Beispiel #3
0
    def test_ant_moves_home_if_it_has_food(self):
        ant = Ant(nest=Nest(0, 0), chemicals=Chemicals())
        ant.food = 1
        ant.last_direction = NW
        ant.location = Location(10, 10)
        ant.chemicals.search[9, 9] = 1.0

        ant.tick()

        self.assertEqual(
            Location(9, 9),
            ant.location,
        )
Beispiel #4
0
    def test_if_returning_and_all_search_directions_are_the_same_move_away_from_found(
            self):
        chemicals = Chemicals()
        nest = Nest(0, 0)

        ant = Ant(nest=nest, chemicals=chemicals)
        ant.food = 1
        ant.last_direction = NW
        ant.location = Location(10, 10)
        chemicals.found[:, :] = 1
        chemicals.found[9, 9] = 0

        ant.tick()

        self.assertEqual(Location(9, 9), ant.location)