def start_game_with_players(players, game_duration: int, board_width: int, board_height: int, n_fruits: int, fast_run: bool = False, graphics_off: bool = False, t=None): if len(players) < 1: print("The number of agents must be at least 1.") env = SnakesBackendSync(players, grid_size=Grid2DSize(board_width, board_height), n_fruits=n_fruits, game_duration_in_turns=game_duration) env.run_game(human_speed=not fast_run, render=not graphics_off, t=t)
def get_fitness(moves_sequence: tuple) -> float: n_agents = 20 static_agent = StaticAgent(moves_sequence) opponents = [RandomPlayer() for _ in range(n_agents - 1)] players = [static_agent] + opponents board_width = 40 board_height = 40 n_fruits = 50 game_duration = len(moves_sequence) env = SnakesBackendSync(players, grid_size=Grid2DSize(board_width, board_height), n_fruits=n_fruits, game_duration_in_turns=game_duration, random_seed=42) env.run_game(human_speed=False, render=False) np.random.seed() return env.game_state.snakes[0].length + env.game_state.snakes[0].alive