Esempio n. 1
0
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}")
Esempio n. 2
0
def main():

    # Setup a game
    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)
    agent_home = Agent("home agent", human=True)
    agent_away = Agent("home agent", human=True)
    game = botbowl.Game(1,
                        home,
                        away,
                        agent_home,
                        agent_away,
                        config,
                        arena=arena,
                        ruleset=ruleset)
    game.init()

    # Enable forward model
    game.enable_forward_model()
    step_id = game.get_step()

    # Force determinism?
    # game.set_seed(1)  # Force determinism

    # Take some actions
    game.step(Action(ActionType.START_GAME))
    game.step(Action(ActionType.HEADS))
    game.step(Action(ActionType.RECEIVE))

    # Kicking team is random if you didn't set the seed
    print("Home is kicking: ", game.get_kicking_team() == game.state.home_team)
    print_available_action_types(game)

    # Revert state and save the steps
    steps = game.revert(step_id)

    # Print available actions: Should only contain START_GAME
    print_available_action_types(game)

    # step the game forward again
    game.forward(steps)
    print("Home is kicking: ", game.get_kicking_team() == game.state.home_team)
    print_available_action_types(game)
Esempio n. 3
0
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}")
Esempio n. 4
0
import botbowl

config = botbowl.load_config("bot-bowl-iii")
config.competition_mode = False
config.pathfinding_enabled = False  # disabled for speed
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)


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 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 == ""