Example #1
0
def get_game(id):
    game = session.query(Game).filter(Game.id_game == int(id)).one()
    game_stats = session.query(GameStats).filter(
        Game.id_game == int(id)).one_or_none()

    return json_response({
        'status': status.OK,
        'body': format_game(game, game_stats),
    })
Example #2
0
def get_game_state(userid):
    player = session.query(Player).filter_by(userid_player=userid).first()
    if player is None:
        raise WithingsException(*status.USER_NOT_FOUND)

    p = g._get_by_userid(userid)
    return json_response({'status': status.OK, 'body': g.dump_state(p)})
Example #3
0
def get_stats():

    gs = session.query(GameStats)
    n_game = gs.count()
    n_good_wins = gs.filter(GameStats.good_wins).count()

    stats = {
        'n_game': n_game,
        'n_evil_wins': n_game - n_good_wins,
        'n_good_wins': n_good_wins,
        'r_evil_wins': (n_game - n_good_wins) / n_game,
        'r_good_wins': n_good_wins / n_game,
    }
    print('toot', stats)

    # ideas of badges / achievements

    # hidden merlin :
    # 1 point for voting for a known evil guy as merlin
    # 3 point for putting for a known evil guy as merlin
    # mean over game where the player is merlin

    # i'm not that guy :
    # most lady of the lake verified galahad

    return json_response({
        'status': status.OK,
        'body': stats,
    })
Example #4
0
def join_game(userid):
    player = session.query(Player).filter_by(userid_player=userid).first()
    if player is None:
        raise WithingsException(*status.USER_NOT_FOUND)

    g.add_player(player)

    return json_response({'status': status.OK, 'body': "Ok!"})
Example #5
0
def check_player(userid):
    player = session.query(Player).filter_by(userid_player=userid).first()
    if player is None:
        raise WithingsException(*status.USER_NOT_FOUND)

    p = g._get_by_userid(userid)
    if not p:
        raise WithingsException(*status.NOT_IN_THE_GAME)

    return p
Example #6
0
def player_get(userid):
    player = session.query(Player).filter_by(userid_player=userid).first()

    if player is None:
        raise WithingsException(*status.USER_NOT_FOUND)

    return json_response({
        'status': status.OK,
        'body': utils.format_player(player)
    })
Example #7
0
def get_list_games():
    games = session.query(Game)
    # TODO paginate

    return json_response({
        'status': status.OK,
        'body': {
            'n_game': games.count(),
            'games': [format_game(g_) for g_ in games.all()],
        }
    })
Example #8
0
def player_create(userid, info):
    player = session.query(Player).filter_by(userid_player=userid).first()

    if player is not None:
        raise WithingsException(*status.USER_ALREADY_EXISTS)

    info = json.loads(info)
    player = Player(userid, info)
    session.add(player)

    session.commit()
    return json_response({
        'status': status.OK,
        'body': {
            "id": player.id_player
        }
    })