Esempio n. 1
0
def test_team():
    config = load_config("ff-11")
    ruleset = load_rule_set(config.ruleset)
    home = load_team_by_filename("human", ruleset)
    away = load_team_by_filename("human", ruleset)
    away_agent = make_bot("random")
    home_agent = make_bot("random")
    game = Game(1, home, away, home_agent, away_agent, config)
    game.init()
    assert game.state.game_over
    assert game.end_time is not None
Esempio n. 2
0
def get_game(fast_mode=True, human_agents=True):
    config = load_config("bot-bowl-iii")
    config.fast_mode = fast_mode
    ruleset = load_rule_set(config.ruleset)
    home = load_team_by_filename("human", ruleset)
    away = load_team_by_filename("human", ruleset)
    away_agent = Agent("Human 1", human=True, agent_id=1) if human_agents else make_bot("random")
    home_agent = Agent("Human 2", human=True, agent_id=2) if human_agents else make_bot("random")
    game = Game(1, home, away, home_agent, away_agent, config)
    game.init()

    game.enable_forward_model()

    return game
Esempio n. 3
0
 def _get_competitor(self, name, init_time):
     try:
         with self.time_limit(init_time):
             return make_bot(name)
     except TimeoutException as e:
         print(f"{name} timout while initializing:", e)
     except Exception as e:
         print(f"{name} crashed while initializing:", e)
     return None
Esempio n. 4
0
def create():
    data = json.loads(request.data)
    bot_list = api.get_bots()
    # make_bot or Agent depending on choice... (unknown name => human)
    homePlayer = data['game']['home_player']
    if homePlayer in bot_list:
        homeAgent = make_bot(homePlayer)
    else:
        homeAgent = Agent("Player 1", human=True)

    awayPlayer = data['game']['away_player']
    if awayPlayer in bot_list:
        awayAgent = make_bot(awayPlayer)
    else:
        awayAgent = Agent("Player 1", human=True)

    game = api.new_game(data['game']['home_team_name'],
                        data['game']['away_team_name'], homeAgent, awayAgent)
    return json.dumps(game.to_json())
Esempio n. 5
0
 def __init__(self, bot_id, team):
     self.bot_id = bot_id
     self.bot = make_bot(bot_id)
     self.team = team
     super(Competitor, self).__init__(self.bot.name, human=False)
     self.remote, self.work_remote = Pipe()
     p = Process(target=self.run,
                 args=(self.work_remote, self.remote, self.bot))
     p.daemon = True  # if the main process crashes, we should not cause things to hang
     p.start()
     self.remote.close()
Esempio n. 6
0
 def _get_competitor(self, name, init_time):
     bot = None
     try:
         with stopit.ThreadingTimeout(init_time) as to_ctx_mgr:
             assert to_ctx_mgr.state == to_ctx_mgr.EXECUTING
             bot = make_bot(name)
         if to_ctx_mgr.state == to_ctx_mgr.EXECUTED:
             return bot
         else:
             print(f"{name} timed out while initializing.")
     except Exception as e:
         print(f"{name} crashed while initializing:", e)
     return bot
Esempio n. 7
0
import ffai.web.server as server
import ffai.web.api as api
from ffai.ai.registry import make_bot
from ffai.core.model import Agent

# Import this to register MyScriptedBot with id 'scripted'
import examples.scripted_bot_example

# Create some games
api.new_game(home_team_id="orc-1",
             away_team_id="human-1",
             home_agent=make_bot("random"),
             away_agent=Agent("Player 2", human=True))

api.new_game(home_team_id="orc-1",
             away_team_id="human-1",
             home_agent=make_bot("scripted"),
             away_agent=Agent("Player 2", human=True))

api.new_game(home_team_id="human-1",
             away_team_id="human-2",
             home_agent=Agent("Player 1", human=True),
             away_agent=Agent("Player 2", human=True))

# Run server
server.start_server(debug=True, use_reloader=True)
Esempio n. 8
0
import ffai.web.server as server
import ffai.web.api as api
from ffai.ai.registry import make_bot
from ffai.core.model import Agent

# Import this to register MyScriptedBot with id 'scripted'
import examples.scripted_bot_example
import examples.grodbot

# Create some games
api.new_game(home_team_id="orc-1",
             away_team_id="human-1",
             home_agent=make_bot("random"),
             away_agent=Agent("Player 2", human=True))

api.new_game(home_team_id="orc-1",
             away_team_id="human-1",
             home_agent=make_bot("scripted"),
             away_agent=Agent("Player 2", human=True))

api.new_game(home_team_id="human-1",
             away_team_id="human-2",
             home_agent=Agent("Player 1", human=True),
             away_agent=Agent("Player 2", human=True))

api.new_game(home_team_id="orc-1",
             away_team_id="human-1",
             home_agent=make_bot("GrodBot"),
             away_agent=make_bot("GrodBot"))

# Run server
Esempio n. 9
0
from ffai.core.load import *
from ffai.ai.registry import register_bot, make_bot

import examples.scripted_bot_example

# Load configurations, rules, arena and teams
config = load_config("bot-bowl-i.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)
config.competition_mode = False

# Play 5 games as away
for i in range(5):
    away_agent = make_bot('grodbot')
    away_agent.name = 'grodbot'
    home_agent = make_bot('scripted')
    home_agent.name = 'scripted'
    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)

# Play 5 games as home
for i in range(5):
Esempio n. 10
0
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):
        away_agent = make_bot("my-random-bot")
        home_agent = make_bot("my-random-bot")

        game = 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")
Esempio n. 11
0
#!/usr/bin/env python3

import ffai.web.server as server
import ffai.web.api as api
from ffai.ai.registry import make_bot
from ffai.core.model import Agent

# Import this to register bots
import sagelingbot

api.new_game(home_team_id="orc-1",
             away_team_id="human-1",
             home_agent=make_bot("SagelingBot"),
             away_agent=make_bot("SagelingBot"))

# Run server
server.start_server(debug=True, use_reloader=False)
Esempio n. 12
0
    # 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)

    # 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 2"
        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))
Esempio n. 13
0
from timeit import default_timer as timer
import random

from copy import deepcopy
from ffai.ai.registry import make_bot

import cProfile
import io
import pstats
#from pstats import SortKey

config = load_config("gym-11")
ruleset = load_rule_set(config.ruleset)
home = load_team_by_filename("human", ruleset)
away = load_team_by_filename("human", ruleset)
away_agent = make_bot("random")
home_agent = make_bot("random")


def run_game_with_forward_model():
    game = Game(1, home, away, home_agent, away_agent, config)
    game.enable_forward_model()
    game.init()


def run_game_without_forward_model():
    game = Game(1, home, away, home_agent, away_agent, config)
    game.init()


def normal_games():