Exemple #1
0
def get_all_players():
  pl = Playoff(
    client_id=client_id,
    client_secret=client_secret,
    type='client'
    ,allow_unsecure=True
  )
  players = pl.get(
      route='/admin/players',
      query={}
  )
  return players
Exemple #2
0
def get_action_template(action_id):
    pl = Playoff(
        client_id=client_id,
        client_secret=client_secret,
        type='client'
        ,allow_unsecure=True
        ,hostname='playoffgenerali.it'
    )
    action = pl.get(
        route='/design/versions/latest/actions/'+action_id,
        query={}
    )
    return action
Exemple #3
0
def client():
    global pl
    pl = Playoff(
        version='v1',
        client_id="YWY1ZTNhNDYtZmFmNi00MzNiLWIxZDktODFlNTVjYjEzNjA0",
        client_secret=
        "NDFhMDgzYWQtZGI1ZS00YTE3LWI5YTktYzliNmQ2YmI4NGJiNzg2YzIyODAtNTg1My0xMWU0LWE4MDEtZjkwOTJkZGEwOWUz",
        type='client')
    players = pl.get(route='/game/players')
    html = "<ul>"
    for player in players['data']:
        html += "<li>" + str(player['alias']) + "</li>"
    html += "</ul>"
    return html
Exemple #4
0
def delete_challenge(challenge_id):
    pl = Playoff(
        client_id=client_id,
        client_secret=client_secret,
        type='client'
    )
    challenge_template_id =  'challenge_tmp_max_01'
    action = get_action_template(challenge_template_id)
    action['id'] = challenge_id


    action = pl.delete(
        route='/design/versions/latest/actions/'+challenge_id
    )
    return action
Exemple #5
0
def login():
    global pl
    pl = Playoff(
        version='v1',
        client_id="YmE1MDQzMmUtMmU4MC00YWU4LWEyZGMtODJiMDQ3NGY2NDNh",
        client_secret=
        "ZTczNTM3N2UtMmE3MS00ZDdkLWI4NzctZjM3ZDFjZGI5ZGQ4YjM0Y2ViNTAtNTg1My0xMWU0LWE4MDEtZjkwOTJkZGEwOWUz",
        type='code',
        redirect_uri='http://127.0.0.1:5000/code')
    if 'username' in session:
        return redirect(url_for('home'))
    else:
        url = pl.get_login_url()
        return """
      <h2> Please Login to your Playoff Account </h1>
      <h2><a href="%s">Login</a></h2>
    """ % url
Exemple #6
0
def test_jwt():
  token = Playoff.createJWT(
    client_id=client_id,
    client_secret=client_secret,
    player_id='*****@*****.**'
  )
  print("token-> " )
  print(str(token))
Exemple #7
0
def test_store():
  pl = Playoff(
    version = 'v1',
    client_id=client_id,
    client_secret=client_secret,
    type = 'client',
    store = store
  )
Exemple #8
0
def test_auth():
  try:
    pl = Playoff(
      version = 'v1',
      client_id=client_id,
      client_secret=client_secret,
      type = 'code'
    )
  except PlayoffException as e:
    assert e.name == 'init_failed'

  pl = Playoff(
    version = 'v1',
    client_id=client_id,
    client_secret=client_secret,
    type = 'code',
    redirect_uri = 'https://localhost:3000/auth/callback'
  )
  print(str(pl.get_login_url()))
Exemple #9
0
def test_wrong_init():
  try:
    pl = Playoff(
      version = 'v1',
      client_id = "wrong_id",
      client_secret = "wrong_secret",
      type = 'client'
    )
  except PlayoffException as e:
    assert 'Client authentication failed' in e.message
Exemple #10
0
def update_challenge(challenge_id):
    pl = Playoff(
        client_id=client_id,
        client_secret=client_secret,
        type='client'
    )
    challenge_template_id =  'challenge_template'
    action = get_action_template(challenge_id)
    action.pop('id', None)#there cannot be an id for PATCH
    action['name'] = 'ch1_mod'
    action['rules'][0]['rewards'][0]['value'] = "1100"
    action['rules'][0]['rewards'][1]['value'] = "1200"
    action['rules'][0]['rewards'][2]['value'] = "1300"
    action['rules'][1]['rewards'][0]['value'] = "0"
    action['rules'][1]['rewards'][1]['value'] = "0"
    action['rules'][1]['rewards'][2]['value'] = "0"

    action = pl.patch(
        route = '/design/versions/latest/actions/'+challenge_id,
        body = action
    )
    return action
Exemple #11
0
def create_challenge(challenge_id):
    pl = Playoff(
        client_id=client_id,
        client_secret=client_secret,
        type='client'
    )
    challenge_template_id =  'challenge_template'
    action = get_action_template(challenge_template_id)
    action['id'] = challenge_id
    action['name'] = 'ch1_gen'
    action['rules'][0]['rewards'][0]['value'] = "110"
    action['rules'][0]['rewards'][1]['value'] = "120"
    action['rules'][0]['rewards'][2]['value'] = "130"
    action['rules'][1]['rewards'][0]['value'] = "0"
    action['rules'][1]['rewards'][1]['value'] = "0"
    action['rules'][1]['rewards'][2]['value'] = "0"

    action = pl.post(
        route='/design/versions/latest/actions',
        body =action
    )
    return action
Exemple #12
0
def setup(args) -> Playoff:
    game=Game()
    verbose=False
    fast=False
    trials=1
    goats : List[Agent] = []
    tigers : List[Agent] = []
    for i in range(len(args)):
        if args[i] == "--verbose":
            verbose = True
            continue
        if args[i] == "--fast":
            fast = True
            continue
        matched=re.match(r'--trials=([0-9]+)',args[i])
        if matched:
            trials = int(matched.group(1))
            continue
        matched=re.match(r'--goat=(.*)',args[i])
        if matched:
            name=matched.group(1)
            clazz=load_class(name)
            agent=clazz(game,Const.MARK_GOAT)
            goats.append((name + " goat",agent))
            continue
        matched=re.match(r'--metagoat\[(.*)\]',args[i])
        if matched:
            parms=matched.group(1)
            agent=metaagent(game,Const.MARK_GOAT,parms)
            goats.append((" metagoat[" + parms + "]",agent))

            continue
        matched=re.match(r'--tiger=(.*)',args[i])
        if matched:
            name=matched.group(1)
            clazz=load_class(name)
            agent=clazz(game,Const.MARK_TIGER)
            tigers.append((name + " tiger",agent))
            continue
        matched=re.match(r'--metatiger\[(.*)\]',args[i])
        if matched:
            parms=matched.group(1)
            agent=metaagent(game,Const.MARK_TIGER,parms)
            tigers.append((" metatiger[" + parms + "]",agent))
            continue
    
    if len(goats) == 0:
        goats.append(('default random goat',RandomAgent(game,Const.MARK_GOAT)))
    if len(tigers) == 0:
        tigers.append(('default random tiger',RandomAgent(game,Const.MARK_TIGER)))
    playoff=Playoff(trials,verbose, fast)
    for (name,agent) in goats:
        playoff.addGoatAgent(name,agent)
    for (name,agent) in tigers:
        playoff.addTigerAgent(name,agent)
    return playoff
Exemple #13
0
    def get_playoff_client(client_id, client_secret, hostname):
        """Return Playoff game instance given his client id , client secret and
        hostname

        :param client_id: Playoff game client id
        :param client_secret: Playoff game client secret
        :param hostname: hostname
        :return: Playoff game instance
        """
        Utility.raise_empty_parameter_exception(
            [client_id, client_secret, hostname])

        logger = MigrationLogger.get_instance()
        logger.info("A new playoff client will be created...")

        from pathlib import Path
        env_path = Path('.') / '.env'
        load_dotenv(dotenv_path=env_path)

        return Playoff(client_id=os.environ[client_id],
                       client_secret=os.environ[client_secret],
                       type='client',
                       allow_unsecure=True,
                       hostname=os.environ[hostname])
Exemple #14
0
from const import Const
from game import Game
import random
from matchup import Matchup
from randomagent import RandomAgent
from shygoatagent import ShyGoatAgent
from playoff import Playoff

game = Game()
playoff = Playoff(trials=10, verbose=False)

playoff.addGoatAgent("shy goat", ShyGoatAgent(game))
playoff.addTigerAgent("random tiger", RandomAgent(game, Const.MARK_TIGER))

playoff.play()
Exemple #15
0
from scaredgoatagent import ScaredGoatAgent
from stats import Stats
from playoff import Playoff
from elusiveGoatAgent import elusiveGoatAgent
from congoat import ConserveGoatAgent
from aggressivegoatagent import AggressiveGoatAgent
from sidehugginggoat import SideHuggingGoat
from SmartGoatAgent import SmartGoatAgent
from randomagent import RandomAgent
from const import Const
from goatAgrosAgent import GoatAgrosAgent
from occamsgoatagent import OccamsGoatAgent
from minmaxagent import MinMaxAgent

game = Game()
playoff = Playoff(trials=1)

# playoff.addGoatAgent("elusive goat",elusiveGoatAgent(game))
# playoff.addGoatAgent("conservative goat",ConserveGoatAgent(game))
# playoff.addGoatAgent("aggressive goat", AggressiveGoatAgent(game))
# playoff.addGoatAgent("side hugging goat", SideHuggingGoat(game))
# playoff.addGoatAgent("smart goat", SmartGoatAgent(game))
# playoff.addGoatAgent("agros goat",GoatAgrosAgent(game))
# playoff.addGoatAgent("occams goat",OccamsGoatAgent(game))
# playoff.addGoatAgent("random goat",RandomAgent(game,Const.MARK_GOAT))
# playoff.addGoatAgent("minmax 1 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=1))
playoff.addGoatAgent("minmax 2 goat",
                     MinMaxAgent(game=game, side=Const.MARK_GOAT, maxDepth=2))
# playoff.addGoatAgent("minmax 3 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=3))

# playoff.addTigerAgent("random tiger",RandomAgent(game,Const.MARK_TIGER))
Exemple #16
0
from scaredgoatagent import ScaredGoatAgent
from stats import Stats
from playoff import Playoff
from elusiveGoatAgent import elusiveGoatAgent
from congoat import ConserveGoatAgent
from aggressivegoatagent import AggressiveGoatAgent
from sidehugginggoat import SideHuggingGoat
from SmartGoatAgent import SmartGoatAgent
from randomagent import RandomAgent
from const import Const
from goatAgrosAgent import GoatAgrosAgent
from occamsgoatagent import OccamsGoatAgent
from minmaxagent import MinMaxAgent

game = Game()
playoff = Playoff(trials = 1000)

# playoff.addGoatAgent("elusive goat",elusiveGoatAgent(game))
# playoff.addGoatAgent("conservative goat",ConserveGoatAgent(game))
# playoff.addGoatAgent("aggressive goat", AggressiveGoatAgent(game))
# playoff.addGoatAgent("side hugging goat", SideHuggingGoat(game))
playoff.addGoatAgent("smart goat", SmartGoatAgent(game))
# playoff.addGoatAgent("agros goat",GoatAgrosAgent(game))
# playoff.addGoatAgent("occams goat",OccamsGoatAgent(game))
# playoff.addGoatAgent("random goat",RandomAgent(game,Const.MARK_GOAT))
# playoff.addGoatAgent("minmax 1 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=1))
#playoff.addGoatAgent("minmax 2 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=2))
#playoff.addGoatAgent("minmax 3 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=3))

# playoff.addTigerAgent("random tiger",RandomAgent(game,Const.MARK_TIGER))
playoff.addTigerAgent("hungry tiger",HungryTigerAgent(game))
Exemple #17
0
from stats import Stats
from playoff import Playoff
from elusiveGoatAgent import elusiveGoatAgent
from congoat import ConserveGoatAgent
from aggressivegoatagent import AggressiveGoatAgent
from sidehugginggoat import SideHuggingGoat
from SmartGoatAgent import SmartGoatAgent
from randomagent import RandomAgent
from const import Const
from goatAgrosAgent import GoatAgrosAgent
from occamsgoatagent import OccamsGoatAgent
from minmaxagent import MinMaxAgent
from cachingminmaxagent import CachedMinMaxAgent

game = Game()
playoff = Playoff(trials = 1)

# playoff.addGoatAgent("elusive goat",elusiveGoatAgent(game))
# playoff.addGoatAgent("conservative goat",ConserveGoatAgent(game))
# playoff.addGoatAgent("aggressive goat", AggressiveGoatAgent(game))
# playoff.addGoatAgent("side hugging goat", SideHuggingGoat(game))
# playoff.addGoatAgent("smart goat", SmartGoatAgent(game))
# playoff.addGoatAgent("agros goat",GoatAgrosAgent(game))
# playoff.addGoatAgent("occams goat",OccamsGoatAgent(game))
# playoff.addGoatAgent("random goat",RandomAgent(game,Const.MARK_GOAT))
# playoff.addGoatAgent("minmax 1 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=1))
playoff.addGoatAgent("cached minmax 2 goat",CachedMinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=2,maxCacheSize=10_000))
# playoff.addGoatAgent("minmax 3 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=3))

# playoff.addTigerAgent("random tiger",RandomAgent(game,Const.MARK_TIGER))
playoff.addTigerAgent("hungry tiger",HungryTigerAgent(game))
from const import Const
from game import Game
import random
from matchup import Matchup
from randomagent import RandomAgent
from shygoatagent import ShyGoatAgent
from agressivetigeragent import AggressiveTigerAgent
from playoff import Playoff

game = Game()
playoff = Playoff(trials=1000)

playoff.addGoatAgent("shy goat", ShyGoatAgent(game, Const.MARK_GOAT))
playoff.addTigerAgent("agressive tiger",
                      AggressiveTigerAgent(game, Const.MARK_TIGER))

playoff.play()
Exemple #19
0
def test_v2():
  pl = Playoff(
    version = 'v2',
    client_id=client_id,
    client_secret=client_secret,
    type = 'code'
  )

  try:
    pl.get(route= '/gege', query= { 'player_id': 'student1' })
  except PlayoffException as e:
    assert 'route does not exist' in e.message

  players = pl.api(method = 'GET', route = '/runtime/players', query = { 'player_id': 'student1', 'limit': 1 })
  assert players['data'] != None
  assert players['data'][0] != None

  try:
    pl.get(route = '/runtime/player')
  except PlayoffException as e:
    assert "The 'player_id' parameter should be specified in the query" in e.message

  player_id = 'student1'
  player = pl.get(route = '/runtime/player', query = { 'player_id': player_id } )
  assert player["id"] == "student1"
  assert player["alias"] == "Student1"
  assert player["enabled"] == True

  pl.get(route = '/runtime/definitions/processes', query = { 'player_id': player_id } )
  pl.get(route ='/runtime/definitions/teams', query = { 'player_id': player_id } )
  pl.get(route = '/runtime/processes', query = { 'player_id': player_id } )
  pl.get(route = '/runtime/teams', query = { 'player_id': player_id } )

  processes = pl.get(route = '/runtime/processes', query = { 'player_id': 'student1', 'limit': 1, 'skip': 4 })
  assert processes["data"][0]["definition"] == "module1"
  assert len(processes["data"]), 1

  new_process = pl.post(route = '/runtime/processes', query = { 'player_id': player_id }, body = { 'definition': 'module1' })
  assert new_process["definition"]['id'] == "module1"
  assert new_process["state"] == "ACTIVE"

  patched_process = pl.patch(
    route = "/runtime/processes/%s" %new_process['id'],
    query = { 'player_id': player_id },
    body = { 'name': 'patched_process', 'access': 'PUBLIC' }
  )

  assert patched_process['name'] == 'patched_process'
  assert patched_process['access'] == 'PUBLIC'

  deleted_process = pl.delete(route = "/runtime/processes/%s" %new_process['id'], query = { 'player_id': player_id })
  assert deleted_process['message'] != None

  raw_data = pl.get(route = '/runtime/player', query = { 'player_id': player_id }, raw = True)
  assert type(raw_data) is str