Exemplo n.º 1
0
 def _run_match(self, match_id, home_team, away_team, home_agent,
                away_agent):
     game = Game(match_id,
                 home_team=deepcopy(home_team),
                 away_team=deepcopy(away_team),
                 home_agent=home_agent,
                 away_agent=away_agent,
                 config=self.config,
                 record=self.record)
     game.config.fast_mode = True
     game.config.competition_mode = True
     print("Starting new match")
     try:
         with stopit.ThreadingTimeout(int(
                 self.config.time_limits.game)) as to_ctx_mgr:
             game.init()
         if to_ctx_mgr.state != to_ctx_mgr.EXECUTED:
             print("Game timed out!")
             game.end_time = time.time()
             game.game_over = True
             game.disqualified_agent = game.actor
             return GameResult(game)
     except Exception as e:
         print(
             f"Game crashed by {game.actor.name if game.actor is not None else 'the framework'}: ",
             e)
         game.disqualified_agent = game.actor
         return GameResult(game, crashed=True)
     return GameResult(game)
Exemplo n.º 2
0
 def setup(self, game: g.Game):
     """
     Move players from the reserves to the pitch
     """
     i = len(game.get_players_on_pitch(self.my_team))
     reserves = game.get_reserves(self.my_team)
     if i == 11 or len(reserves) == 0:
         return m.Action(t.ActionType.END_SETUP)
     player = reserves[0]
     y = 3
     x = 13 if game.is_team_side(m.Square(13, 3), self.my_team) else 14
     return m.Action(t.ActionType.PLACE_PLAYER,
                     player=player,
                     pos=m.Square(x, y + i))
Exemplo n.º 3
0
 def touchback(self, game: g.Game):
     """
     Select player to give the ball to.
     """
     for player in game.get_players_on_pitch(self.my_team, up=True):
         if m.Skill.BLOCK in player.skills:
             return m.Action(t.ActionType.SELECT_PLAYER, player=player)
     return m.Action(t.ActionType.SELECT_NONE)
Exemplo n.º 4
0
 def place_ball(self, game: g.Game):
     """
     Place the ball when kicking.
     """
     left_center = m.Square(7, 8)
     right_center = m.Square(20, 8)
     if game.is_team_side(left_center, self.opp_team):
         return m.Action(t.ActionType.PLACE_BALL, pos=left_center)
     return m.Action(t.ActionType.PLACE_BALL, pos=right_center)
Exemplo n.º 5
0
 def _run_match(self, match_id, home_team, away_team, home_agent, away_agent):
     game = Game(match_id, home_team=deepcopy(home_team), away_team=deepcopy(away_team), home_agent=home_agent, away_agent=away_agent, config=self.config)
     game.config.fast_mode = True
     game.config.competition_mode = True
     try:
         with self.time_limit(int(self.config.time_limits.game_time_limit)):
             game.init()
     except TimeoutException:
         print("Game timed out!")
         # Load from autosave
         #data_path = get_data_path(rel_path=f"auto/{game.game_id}.ffai")
         #game = pickle.load(open(data_path, "rb"))
         game.end_time = time.time()
         return GameResult(game)
     except Exception as e:
         print(f"Game crashed by {game.actor.name if game.actor is not None else 'the framework'}: ", e)
         return GameResult(game, crashed=True)
     return GameResult(game)
Exemplo n.º 6
0
 def _compete(self, match_id, home, away):
     game = Game(match_id,
                 home_team=deepcopy(home.team),
                 away_team=deepcopy(away.team),
                 home_agent=home.bot,
                 away_agent=away.bot,
                 config=self.config)
     game.config.fast_mode = True
     game.config.competition_mode = True
     game.init()
     game.step()
     assert game.state.game_over
     return GameResult(game)
Exemplo n.º 7
0
def run_game(nbr_of_games, enable_forward_model):
    config = ffai.load_config("gym-11")
    config.fast_mode = True
    ruleset = ffai.load_rule_set(config.ruleset)
    home = ffai.load_team_by_filename("human", ruleset)
    away = ffai.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 = ffai.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))
Exemplo n.º 8
0
 def high_kick(self, game: g.Game):
     """
     Select player to move under the ball.
     """
     ball_pos = game.get_ball_position()
     if game.is_team_side(game.get_ball_position(), self.my_team) and \
             game.get_player_at(game.get_ball_position()) is None:
         for player in game.get_players_on_pitch(self.my_team, up=True):
             if m.Skill.BLOCK in player.skills:
                 return m.Action(t.ActionType.PLACE_PLAYER,
                                 player=player,
                                 pos=ball_pos)
     return m.Action(t.ActionType.SELECT_NONE)
Exemplo n.º 9
0
def reverse_x_for_left(game: g.Game, team: m.Team, x: int) -> int:
    if game.is_team_side(m.Square(13, 3), team):
        res = game.state.pitch.width - 1 - x
    else:
        res = x
    return res
Exemplo n.º 10
0
 def add_players_moved(self, game: g.Game, players: List[m.Player]):
     for player in players:
         adjacents: List[m.Square] = game.get_adjacent_squares(player.position, include_occupied=True)
         self.units_friendly[player.position.x][player.position.y] += 1.0
         for adjacent in adjacents:
             self.units_friendly[player.position.x][player.position.y] += 0.5
Exemplo n.º 11
0
 def new_game(self, game: g.Game, team):
     """
     Called when a new game starts.
     """
     self.my_team = team
     self.opp_team = game.get_opp_team(team)
Exemplo n.º 12
0
register_bot('scripted', MyScriptedBot)

if __name__ == "__main__":

    # Load configurations, rules, arena and teams
    config = load_config("bot-bowl-ii")
    config.competition_mode = True
    # config = get_config("ff-7.json")
    # config = get_config("ff-5.json")
    # config = get_config("ff-3.json")
    ruleset = load_rule_set(config.ruleset, all_rules=False)  # We don't need all the rules
    arena = load_arena(config.arena)
    home = load_team_by_filename("human", ruleset)
    away = load_team_by_filename("human", ruleset)

    # Play 100 games
    for i in range(10):
        home_agent = make_bot('scripted')
        home_agent.name = "Scripted Bot 1"
        away_agent = make_bot('scripted')
        away_agent.name = "Scripted Bot 3"
        config.debug_mode = False
        game = 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)