Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
Arquivo: bots.py Projeto: rreche/ffai
            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):
Exemplo n.º 3
0
            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):
Exemplo n.º 4
0
"""
==========================
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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
"""
==========================
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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
Arquivo: bots.py Projeto: sskett/ffai
    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
Exemplo n.º 10
0
            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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
"""
==========================
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)
Exemplo n.º 13
0
Arquivo: bots.py Projeto: DKuan/ffai
    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()