Example #1
0
def create_app():
    """Construct the core application."""
    app = Flask(
        __name__,
        instance_relative_config=False,
        template_folder="templates",
        static_folder="static"
    )

    # Application Configuration
    app.config.from_object(conf)
    app.json_encoder = GameJSONEncoder

    # list of all available agents
    app.players = [
        'Human',  # this should be "interactive"
        'RandomAgent',
        'GreedyAgent',
        'AlphaBetaAgent',
        'AlphaBetaFast1Agent',
    ]

    # parameters for games
    app.games = dict()
    app.params = dict()
    app.actions = dict()
    app.terrains = dict()
    app.scenarios = list()

    # this is for the control of data collection
    app.collecting = False

    def collect_config():
        if app.collecting:
            return

        app.collecting = True
        try:
            collect()
            app.scenarios = [k for k, v in TMPL_SCENARIOS.items() if 'offline' not in v]
            app.terrains = {v['level']: v for k, v in TMPL_TERRAIN_TYPE.items()}
        except Exception as e:
            logger.error(f'could not collect configuration! {e}')
        finally:
            app.collecting = False

    app.collect_config = collect_config

    with app.app_context():
        # Import parts of our application
        from . import routes
        app.register_blueprint(routes.main)

        return app
Example #2
0
import threading
import time

from flask import Flask, render_template, g, redirect, url_for, send_from_directory
from flask_babel import Babel, gettext
from flask_sockets import Sockets
builtins._ = lambda x, *args, **kwargs: gettext(x) % (args or kwargs)

from lykan import gameengine, util, cards

logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
app = Flask(__name__)
babel = Babel(app)
sockets = Sockets(app)
app.games = {}

VOICE = _("<Voice>Brian</Voice>")
_TRANSLATIONS_DIR = os.path.join(os.path.abspath(__file__ + "/.."),
                                 "translations")
KNOWN_LANGS = ["en"] + [
    lang for lang in os.listdir(_TRANSLATIONS_DIR) if os.path.exists(
        os.path.join(_TRANSLATIONS_DIR, lang, "voice")) and lang != "en"
]


@babel.localeselector
def get_locale():
    return getattr(g, "current_locale", "en")

Example #3
0
from flask import render_template
from flask import redirect
from flask import request
from flask import url_for
from config import *
from casinochain import *
from lottogame import *
from cointossgame import *
import json

app = Flask(__name__)

# Enable Lotto and Coin Toss games
app.NIST_GAMES_AVAILABLE = {'Lotto': LottoGame, 'CoinToss': CoinTossGame}
app.latest_game_id = 2
app.games = {0: CasinoChain(), 1: CasinoChain()}
app.curr_game_ids = {'Lotto': 0, 'CoinToss': 1}
app.games[0].initialize_first_block(LottoGame())
app.games[1].initialize_first_block(CoinTossGame())

def get_or_current_id(id, game_type):
    if not game_type in app.curr_game_ids:
        return None
    if id is not None:
        id = int(id)
        if id in app.games:
            return id
        return None
    if (app.games[app.curr_game_ids[game_type]].is_active() and not app.games[app.curr_game_ids[game_type]].is_done()):
        return app.curr_game_ids[game_type]
    curr_id = app.latest_game_id
Example #4
0
from flask import Flask, render_template, request, redirect
#from pandas import DataFrame,to_datetime
from dill import load
from asteval import Interpreter
from numpy import mean, inf
from collections import defaultdict, Counter


app = Flask(__name__)
app.vars = {}
app.vars['scoring prob'] = [[0, 0.8437591992934943], [1, 0.6227063044592517], [2, 0.5439440106646353], [3, 0.4285026480500722], [4, 0.37752769474239495], [5, 0.3896667323999211], [6, 0.3950091296409008], [7, 0.40369393139841686], [8, 0.39677744209466265], [9, 0.41600227790432803], [10, 0.39260830051499546], [11, 0.403338898163606], [12, 0.4000619770684847], [13, 0.4083076923076923], [14, 0.4118663594470046], [15, 0.4085207100591716], [16, 0.40458309262468706], [17, 0.40657894736842104], [18, 0.39879062736205595], [19, 0.4022117860930162], [20, 0.3993319725366487], [21, 0.38645635028555886], [22, 0.38565368299267255], [23, 0.383383253027738], [24, 0.36440859447498036], [25, 0.3603967304625199], [26, 0.34375875268415645], [27, 0.3332474890548545], [28, 0.32034294621979736], [29, 0.2737306843267108], [30, 0.25252525252525254], [31, 0.19791666666666666], [32, 0.125], [33, 0.18181818181818182], [34, 0.08823529411764706], [35, 0.11538461538461539], [36, 0.06060606060606061], [37, 0.037037037037037035], [38, 0.14705882352941177], [39, 0.0], [40, 0.08888888888888889], [41, 0.14634146341463414], [42, 0.0], [43, 0.047619047619047616], [44, 0.1], [45, 0.05], [46, 0.05263157894736842], [47, 0.043478260869565216], [48, 0.043478260869565216], [49, 0.1], [50, 0.0]]

app.players = load(open('scoringChamps','rb'))
app.games = load(open('gameData','rb'))

aeval = Interpreter()

#examples loaded when we reload scoringinfo.html. The entries are [Text, Function, Free Throws (where 1 is "yes" and 2 is "no")].
app.examples = [["Only Two Pointers", "2",1], ["A Thirty Foot Four Point Line", "2 if % < 23 else 3 if % < 30 else 4", 1 ],["The Knicks are the First Seed in the East", "-2*exp(-%) + log(1+%)", 1 ], ["The Kings are the First Seed in the West", "2 if 3 <= % <= 5 else 0", 2]]


@app.route('/')
def main():
  return redirect('/index')

@app.route('/index',methods=['GET','POST'])
def index():
	if request.method=='GET':
	
		return render_template('scoringinfo.html', examples = app.examples)
		
Example #5
0
import string
from flask import (
    Flask,
    jsonify,
    redirect,
    render_template,
    request,
    session,
    url_for)

app = Flask(__name__)
# This key is a random string that is used for session cookie management
app.secret_key = "8edca468f5f7bb849e5d8bedb" + str(random.randint(0, 100000))
# Store all games in this map (global variable)
# maps game_id (str) -> Game
app.games = {}
# Store all users in this map
# maps user_id (str) -> User
app.users = {}

ASSETS = {
    'bootstrap_css': 'css/bootstrap.min.css',
    'bootstrap_js': 'js/bootstrap.min.js',
    'd3_js': 'js/d3.v3.min.js',
    'favicon_ico': 'favicon.ico',
    'front_page_js': 'js/front_page.js',
    'game_css': 'css/game.css',
    'game_page_js': 'js/game_page.js',
    'jquery_js': 'js/jquery-2.0.3.min.js',
    'lib_js': 'js/lib.js'}