def dodge(self, game): """ Reroll or not. """ return Action(ActionType.USE_REROLL) # return Action(ActionType.DONT_USE_REROLL) def pickup(self, game): """ Reroll or not. """ return Action(ActionType.USE_REROLL) # return Action(ActionType.DONT_USE_REROLL) def end_game(self, game): """ Called when a game endw. """ winner = game.get_winning_team() print("Casualties: ", game.num_casualties()) if winner is None: print("It's a draw") elif winner == self.my_team: print("I ({}) won".format(self.name)) else: print("I ({}) lost".format(self.name)) # Register MyScriptedBot register_bot('simplebot', SimpleBot)
if action_choice.action_type != ActionType.PLACE_PLAYER: break pos = self.rnd.choice(action_choice.positions) if len( action_choice.positions) > 0 else None player = self.rnd.choice( action_choice.players) if len(action_choice.players) > 0 else None action = Action(action_choice.action_type, pos=pos, player=player) self.actions_taken += 1 return action def end_game(self, game): pass # Register RandomBot register_bot('random', RandomBot) class ProcBot(Agent): def __init__(self, name): super().__init__(name) def act(self, game): # Get current procedure proc = game.state.stack.peek() # Call private function if isinstance(proc, StartGame): return self.start_game(game) if isinstance(proc, CoinTossFlip):
action_choice.positions) > 0 else None player = self.rnd.choice( action_choice.players) if len(action_choice.players) > 0 else None # Make action object action = Action(action_choice.action_type, pos=pos, player=player) # Return action to the framework return action def end_game(self, game): pass # Register the bot to the framework register_bot('my-random-bot', MyRandomBot) if __name__ == "__main__": # Load configurations, rules, arena and teams config = get_config("ff-11-bot-bowl-i.json") ruleset = get_rule_set(config.ruleset) arena = get_arena(config.arena) home = get_team_by_id("human-1", ruleset) away = get_team_by_id("human-2", ruleset) config.competition_mode = False config.debug_mode = False # Play 10 games game_times = [] for i in range(10):
""" ========================== Author: Niels Justesen Year: 2018 ========================== This module contains an example bot that takes random actions. """ from ffai.core.model import Agent from ffai.ai.registry import register_bot class ChrashBot(Agent): def __init__(self, name, seed=None): super().__init__(name) def new_game(self, game, team): pass def act(self, game): v = 1 / 0 return None def end_game(self, game): pass # Register bot register_bot('crash', ChrashBot)
def catch(self, game): return Model.Action(Table.ActionType.END_TURN) def interception(self, game): return Model.Action(Table.ActionType.END_TURN) def gfi(self, game): return Model.Action(Table.ActionType.END_TURN) def dodge(self, game): return Model.Action(Table.ActionType.END_TURN) def pickup(self, game): return Model.Action(Table.ActionType.END_TURN) def end_game(self, game): print("Num steps:", len(self.actions_available)) print("Avg. branching factor:", np.mean(self.actions_available)) winner = game.get_winner() print("Casualties: ", game.num_casualties()) if winner is None: print("It's a draw") elif winner == self: print("I ({}) won".format(self.name)) else: print("I ({}) lost".format(self.name)) print("I took", self.actions_taken, "actions") register_bot('SagelingBot', SagelingBot)
class JustInTimeBot(Agent): def __init__(self, name, seed=None): super().__init__(name) self.my_team = None self.rnd = np.random.RandomState(seed) def new_game(self, game, team): self.my_team = team def act(self, game): while time.time() < game.get_seconds_left(self.my_team): time.sleep(0.01) while True: action_choice = self.rnd.choice(game.state.available_actions) if action_choice.action_type != ActionType.PLACE_PLAYER: break pos = self.rnd.choice(action_choice.positions) if len( action_choice.positions) > 0 else None player = self.rnd.choice( action_choice.players) if len(action_choice.players) > 0 else None action = Action(action_choice.action_type, pos=pos, player=player) return action def end_game(self, game): pass # Register bots register_bot('just-in-time', JustInTimeBot)
""" ========================== Author: Niels Justesen Year: 2018 ========================== This module contains an example bot that takes random actions. """ from ffai.core.model import Agent from ffai.ai.registry import register_bot import time class IdleBot(Agent): def __init__(self, name, seed=None): super().__init__(name) def new_game(self, game, team): pass def act(self, game): time.sleep(1000000) return None def end_game(self, game): pass register_bot('idle', IdleBot)
def __init__(self, name, seed=None): super().__init__(name) self.my_team = None self.rnd = np.random.RandomState(seed) def new_game(self, game, team): self.my_team = team def act(self, game): seconds_left = game.get_seconds_left(self.my_team) time.sleep(seconds_left + game.config.time_limits.disqualification) while True: action_choice = self.rnd.choice(game.state.available_actions) if action_choice.action_type != ActionType.PLACE_PLAYER: break position = self.rnd.choice(action_choice.positions) if len( action_choice.positions) > 0 else None player = self.rnd.choice( action_choice.players) if len(action_choice.players) > 0 else None action = Action(action_choice.action_type, position=position, player=player) return action def end_game(self, game): pass # Register bot register_bot('violator', ViolatorBot)
def __init__(self, name, seed=None): super().__init__(name) v = 1 / 0 def new_game(self, game, team): pass def act(self, game): return None def end_game(self, game): pass # Register bots register_bot('random', RandomBot) register_bot('crash', ChrashBot) register_bot('idle', IdleBot) register_bot('violator', ViolatorBot) register_bot('init-crash', InitCrashBot) register_bot('just-in-time', JustInTimeBot) register_bot('manipulator', ManipulatorBot) class ProcBot(Agent): def __init__(self, name): super().__init__(name) def act(self, game): # Get current procedure
game.state.home_team.state.score = 1000 elif game.away_agent == self: game.state.away_team.state.score = 1000 def act(self, game): if game.home_agent == self: game.state.home_team.state.score = 1000 elif game.away_agent == self: game.state.away_team.state.score = 1000 while True: action_choice = self.rnd.choice(game.state.available_actions) if action_choice.action_type != ActionType.PLACE_PLAYER: break pos = self.rnd.choice(action_choice.positions) if len( action_choice.positions) > 0 else None player = self.rnd.choice( action_choice.players) if len(action_choice.players) > 0 else None action = Action(action_choice.action_type, pos=pos, player=player) return action def end_game(self, game): if game.home_agent == self: game.state.home_team.state.score = 1000 elif game.away_agent == self: game.state.away_team.state.score = 1000 pass # Register bot register_bot('manipulator', ManipulatorBot)
def end_game(self, game): """ Called when a game endw. """ winner = game.get_winning_team() print("Casualties: ", game.num_casualties()) if winner is None: print("It's a draw") elif winner == self.my_team: print("I ({}) won".format(self.name)) else: print("I ({}) lost".format(self.name)) # Register MyScriptedBot register_bot('scripted', MyScriptedBot) if __name__ == "__main__": # Load configurations, rules, arena and teams config = get_config("ff-11.json") config.competition_mode = True # config = get_config("ff-7.json") # config = get_config("ff-5.json") # config = get_config("ff-3.json") ruleset = get_rule_set(config.ruleset, all_rules=False) # We don't need all the rules arena = get_arena(config.arena) home = get_team_by_id("human-1", ruleset) away = get_team_by_id("human-2", ruleset)
""" ========================== Author: Niels Justesen Year: 2018 ========================== This module contains an example bot that takes random actions. """ from ffai.core.model import Agent from ffai.ai.registry import register_bot class InitCrashBot(Agent): def __init__(self, name, seed=None): super().__init__(name) v = 1 / 0 def new_game(self, game, team): pass def act(self, game): return None def end_game(self, game): pass # Register bots register_bot('init-crash', InitCrashBot)
def __init__(self, name, seed=None): super().__init__(name) v = 1 / 0 def new_game(self, game, team): pass def act(self, game): return None def end_game(self, game): pass # Register bots register_bot('random', RandomBot) register_bot('crash', ChrashBot) register_bot('idle', IdleBot) register_bot('violator', ViolatorBot) register_bot('init-crash', InitCrashBot) class ProcBot(Agent): def __init__(self, name): super().__init__(name) def act(self, game): # Get current procedure proc = game.state.stack.peek()