コード例 #1
0
    def test_food_in_env_no_get_idx(self):
        model = PrimaVita(log_dir_info="test",
                          params_dic={"initial_population": 1})

        # Test dead player
        model.players = [1]
        food_env = model.food_in_env(model.players[0])

        self.assertEqual(food_env, -1)

        # Test food nearby
        model.players = [
            Player(i=0,
                   log_dir="Players_Data_test",
                   tob=10,
                   x=50,
                   y=500,
                   energy=200)
        ]
        model.food_particles = [Particle(x=64, y=514), Particle(x=45, y=502)]

        vec, distances = model.food_in_env(model.players[0])
        self.assertEqual(vec, [14, 14, -5, 2])
        self.assertEqual(distances, [19.79898987322333, 5.385164807134504])

        shutil.rmtree("Players_Data_test")
コード例 #2
0
    def test_food_nearby(self):
        model = PrimaVita(log_dir_info="test",
                          params_dic={"initial_population": 1})

        # Test dead player
        model.players = [1]
        food = model.food_nearby(model.players[0])

        self.assertEqual(food, -1)

        # Test food nearby
        model.players = [
            Player(i=0,
                   log_dir="Players_Data_test",
                   tob=10,
                   x=50,
                   y=500,
                   energy=200)
        ]
        model.food_particles = [Particle(x=64, y=514), Particle(x=45, y=502)]

        food = model.food_nearby(model.players[0])
        self.assertEqual(food, 0)

        shutil.rmtree("Players_Data_test")
コード例 #3
0
    def test_check_particles(self):
        model = PrimaVita(log_dir_info="test")

        model.food_particles = [
            Particle(x=64, y=514),
            Particle(x=10, y=502),
            Particle(x=60, y=514),
            Particle(x=12, y=502)
        ]
        model.check_particles()

        self.assertEqual(model.food_particles[2], 0)
        self.assertEqual(model.food_particles[3], 0)

        shutil.rmtree("Players_Data_test")