def test_random_comp(): home_agent = botbowl.make_bot("random") away_agent = botbowl.make_bot("random") comp = botbowl.Competition(home_agent, away_agent, home, away, config, ruleset, arena) comp.run()
def main(): # Load configurations, rules, arena and teams config = botbowl.load_config("bot-bowl-iii") config.competition_mode = False config.pathfinding_enabled = False ruleset = botbowl.load_rule_set(config.ruleset) arena = botbowl.load_arena(config.arena) home = botbowl.load_team_by_filename("human", ruleset) away = botbowl.load_team_by_filename("human", ruleset) config.competition_mode = False config.debug_mode = False # Play 100 games game_times = [] wins = 0 draws = 0 n = 100 is_home = True tds_away = 0 tds_home = 0 for i in range(n): if is_home: away_agent = botbowl.make_bot('random') home_agent = botbowl.make_bot('my-a2c-bot') else: away_agent = botbowl.make_bot('my-a2c-bot') home_agent = botbowl.make_bot("random") game = botbowl.Game(i, home, away, home_agent, away_agent, config, arena=arena, ruleset=ruleset) game.config.fast_mode = True print("Starting game", (i + 1)) game.init() print("Game is over") winner = game.get_winner() if winner is None: draws += 1 elif winner == home_agent and is_home: wins += 1 elif winner == away_agent and not is_home: wins += 1 tds_home += game.get_agent_team(home_agent).state.score tds_away += game.get_agent_team(away_agent).state.score print(f"Home/Draws/Away: {wins}/{draws}/{n-wins-draws}") print(f"Home TDs per game: {tds_home/n}") print(f"Away TDs per game: {tds_away/n}")
def run_agent(registration_name, port, token): """ Starts a server that hosts an agent. """ agent = botbowl.make_bot(registration_name) server = PythonSocketServer(agent, port, token) server.run()
def main(): # Load configurations, rules, arena and teams config = botbowl.load_config("bot-bowl-iii") config.competition_mode = False config.pathfinding_enabled = True # config = get_config("gym-7.json") # config = get_config("gym-5.json") # config = get_config("gym-3.json") ruleset = botbowl.load_rule_set( config.ruleset, all_rules=False) # We don't need all the rules arena = botbowl.load_arena(config.arena) home = botbowl.load_team_by_filename("human", ruleset) away = botbowl.load_team_by_filename("human", ruleset) num_games = 10 wins = 0 tds = 0 # Play 10 games for i in range(num_games): home_agent = botbowl.make_bot('scripted') home_agent.name = "Scripted Bot" away_agent = botbowl.make_bot('random') away_agent.name = "Random Bot" config.debug_mode = False game = botbowl.Game(i, home, away, home_agent, away_agent, config, arena=arena, ruleset=ruleset) game.config.fast_mode = True print("Starting game", (i + 1)) start = time.time() game.init() end = time.time() print(end - start) wins += 1 if game.get_winning_team() is game.state.home_team else 0 tds += game.state.home_team.state.score print(f"won {wins}/{num_games}") print(f"Own TDs per game={tds/num_games}")
def test_illegal_actions(capsys): home_agent = botbowl.make_bot("random") away_agent = botbowl.ai.bots.IllegalActionBot("illegal") comp = botbowl.Competition(home_agent, away_agent, home, away, config, ruleset, arena) comp.run() out, err = capsys.readouterr() assert err == "" assert out.find("Action not allowed {'action_type': 'USE_APOTHECARY'") >= 0
def worker(remote, parent_remote, env: BotBowlWrapper, worker_id): parent_remote.close() steps = 0 tds = 0 tds_opp = 0 next_opp = botbowl.make_bot('random') ppcg_wrapper: Optional[PPCGWrapper] = env.get_wrapper_with_type(PPCGWrapper) while True: command, data = remote.recv() if command == 'step': steps += 1 action, dif = data[0], data[1] if ppcg_wrapper is not None: ppcg_wrapper.difficulty = dif (spatial_obs, non_spatial_obs, action_mask), reward, done, info = env.step(action) game = env.game tds_scored = game.state.home_team.state.score - tds tds_opp_scored = game.state.away_team.state.score - tds_opp tds = game.state.home_team.state.score tds_opp = game.state.away_team.state.score if done or steps >= reset_steps: # If we get stuck or something - reset the environment if steps >= reset_steps: print("Max. number of steps exceeded! Consider increasing the number.") done = True env.root_env.away_agent = next_opp spatial_obs, non_spatial_obs, action_mask = env.reset() steps = 0 tds = 0 tds_opp = 0 remote.send((spatial_obs, non_spatial_obs, action_mask, reward, tds_scored, tds_opp_scored, done)) elif command == 'reset': steps = 0 tds = 0 tds_opp = 0 env.root_env.away_agent = next_opp spatial_obs, non_spatial_obs, action_mask = env.reset() remote.send((spatial_obs, non_spatial_obs, action_mask, 0.0, 0, 0, False)) elif command == 'swap': next_opp = data elif command == 'close': break
def run_game(nbr_of_games, enable_forward_model): config = botbowl.load_config("gym-11") config.fast_mode = True ruleset = botbowl.load_rule_set(config.ruleset) home = botbowl.load_team_by_filename("human", ruleset) away = botbowl.load_team_by_filename("human", ruleset) away_agent = Agent("Human 1", human=True, agent_id=1) home_agent = Agent("Human 2", human=True, agent_id=2) seed = 0 random_agent = botbowl.make_bot('random') random_agent.rnd = np.random.RandomState(seed) for _ in range(nbr_of_games): game = Game(seed, home, away, home_agent, away_agent, config) game.init() if enable_forward_model: game.enable_forward_model() while not game.state.game_over: game.step(random_agent.act(game))
#!/usr/bin/env python3 from scripted_bot_example import * import botbowl as botbowl import time as time config = botbowl.load_config("bot-bowl-iii") config.competition_mode = False config.pathfinding_enabled = True config.debug_mode = False ruleset = botbowl.load_rule_set(config.ruleset, all_rules=False) # We don't need all the rules arena = botbowl.load_arena(config.arena) home = botbowl.load_team_by_filename("human", ruleset) away = botbowl.load_team_by_filename("human", ruleset) # Play 10 games for i in range(10): home_agent = botbowl.make_bot('scripted') home_agent.name = "Bot 1" away_agent = botbowl.make_bot('scripted') away_agent.name = "Bot 2" game = botbowl.Game(i, home, away, home_agent, away_agent, config, arena=arena, ruleset=ruleset) game.config.fast_mode = True print("Starting game", (i+1)) start = time.time() game.init() end = time.time() print(end - start)
# Register the bot to the framework botbowl.register_bot('search-bot', SearchBot) # Load configurations, rules, arena and teams config = botbowl.load_config("bot-bowl-iii") ruleset = botbowl.load_rule_set(config.ruleset) arena = botbowl.load_arena(config.arena) home = botbowl.load_team_by_filename("human", ruleset) away = botbowl.load_team_by_filename("human", ruleset) config.competition_mode = False config.debug_mode = False config.fast_mode = True config.pathfinding_enabled = False # Play a game bot_a = botbowl.make_bot("search-bot") bot_b = botbowl.make_bot("search-bot") game = botbowl.Game(1, home, away, bot_a, bot_b, config, arena=arena, ruleset=ruleset) print("Starting game") game.init() print("Game is over")