Esempio n. 1
0
def killActiveGames():
    games = api.get_games(api_key)
    if not games:
        print("No active games found")
    for g in games:
        if g["active"]:
            api.end_game(api_key, g["gameId"])
            print("Ended game: " + g["gameId"])
Esempio n. 2
0
def main():
    mode = ""
    if (len(sys.argv) > 1):
        mode = str(sys.argv[1])

    if mode == "reset":
        games = api.get_games(api_key)
        for g in games:
            if g["active"]:
                api.end_game(api_key, g["gameId"])
                print("Ended game: " + g["gameId"])

    elif mode == "test":
        game.new_game(map_name)
        print("Starting game: " + game.game_state.game_id)
        game.start_game()

        getInfo()
        game.end_game()

    else:
        game.new_game(map_name)
        print("Starting game: " + game.game_state.game_id)
        game.start_game()

        totalQueueHappiness = 0.0

        while game.game_state.turn < game.game_state.max_turns:
            state = game.game_state
            happinessLastTurn = state.total_happiness

            take_turn()

            state = game.game_state
            for message in state.messages:
                print(message + " " + "Happiness: " +
                      str(state.total_happiness) + ", Growth " +
                      str(state.total_happiness - happinessLastTurn) +
                      ", Q-growth " + str(state.queue_happiness))
            for error in state.errors:
                print("Error: " + error)

            totalQueueHappiness += game.game_state.queue_happiness

        score = str(game.get_score()["finalScore"])

        print("Done with game: " + game.game_state.game_id)
        print("Remaining cash: " + str(math.floor(game.game_state.funds)))
        print("Scoring: Population: " +
              str(15 * int(game.get_score()["finalPopulation"])) + " (pop: " +
              str(game.get_score()["finalPopulation"]) + "), happiness: " +
              str(math.floor(game.get_score()["totalHappiness"] / 10)) +
              " (queue: " + str(math.floor(totalQueueHappiness / 10)) +
              ") and co2: -" + str(game.get_score()["totalCo2"]))
        print("Final score was: " + score)
Esempio n. 3
0
def main(map_name, setup, take_turn):
    mode = ""
    if (len(sys.argv) > 1):
        mode = str(sys.argv[1])
    if mode == "reset":
        games = api.get_games(api_key)
        for g in games:
            if g["active"]:
                api.end_game(api_key, g["gameId"])
                print("Ended game: " + g["gameId"])
    elif mode == "test":
        game.new_game(map_name)
        print("Starting game: " + game.game_state.game_id)
        game.start_game()
        get_info()
        game.end_game()
    else:
        game.new_game(map_name)
        print("Starting game: " + game.game_state.game_id)
        game.start_game()
        total_queue_happiness = 0.0
        setup(game) # initial setup
        turn_info = None
        while game.game_state.turn < game.game_state.max_turns:
            state = game.game_state
            happiness_last_turn = state.total_happiness
            try:
                turn_info = take_turn(game) # take turn
            except Exception as ex:
                print(traceback.format_exc())
                print(ex)
                game.end_game()
                return -1
            state = game.game_state
            for message in state.messages:
                print(message + " " + "Happiness: " + str(math.floor(state.total_happiness)) +
                    ", Growth " + str(math.floor(state.total_happiness - happiness_last_turn)) +
                    ", Q-growth " + str(math.floor(state.queue_happiness)))
            for error in state.errors:
                print("Error: " + error)
            total_queue_happiness += game.game_state.queue_happiness
        score = str(game.get_score()["finalScore"])
        print("Done with game: " + game.game_state.game_id)
        print("Remaining cash: " + str(math.floor(game.game_state.funds)))
        print("Scoring: Population: " + str(15 * int(game.get_score()["finalPopulation"])) + " (pop: " + str(game.get_score()["finalPopulation"]) +
            "), happiness: " + str(math.floor(game.get_score()["totalHappiness"] / 10)) +
            " (queue: " + str(math.floor(total_queue_happiness / 10)) +
            ") and co2: -" + str(game.get_score()["totalCo2"]))
        print("Final score was: " + score)
        if turn_info is not None:
            for k, v in sorted(turn_info.items(), key=lambda item: item[1], reverse=True):
                print('{}\t{}\t{}'.format(str(v), str(k[0]), str(k[1])))
        memory.append((int(score), game.game_state.game_id))
        return int(score)
    return None
Esempio n. 4
0
def router(paramstring):
    params = dict(parse_qsl(sys.argv[2][1:]))
    params.pop('sport')
    if params:
        play_me = params.get('play_me')
        scoreboard_link = params.get('scoreboard')
        boxscores_link = params.get('boxscores')
        teamstats_link = params.get('teamstats')
        highlights_link = params.get('highlights')
        playbyplay_link = params.get('playbyplay')
        game_obj = params.get('game_obj')
        title = params.get('title')
        link = params.get('link')
        endpoint = params.get('endpoint')
        page = params.get('page')

        #Plays selected highlight clip
        if play_me:
            play_item = xbmcgui.ListItem(path=play_me)
            xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)

        elif endpoint:
            if endpoint == 'replays':
                if link:
                    replays.show_qualities(link, title)
                elif page is None:
                    from .. import checks
                    okayd = checks.checkPin()
                    if okayd is False:
                        ok = xbmcgui.Dialog().ok(
                            'Sports Guru',
                            'You need a valid pin in order to use this section of the add-on.'
                        )
                        quit()
                    replays.get_games()
                else:
                    replays.get_games(page)
            elif endpoint == 'today':
                game_list = nba_api.get_games()
                nba_api.display_games(game_list)
            elif endpoint == 'details':
                nba_api.display_gameoptions(game_obj)
            elif endpoint == 'standings':
                standings_list = nba_api.get_standings()
                standings_window = standings.Score()
                standings_window.setup(standings_list)
                standings_window.doModal()
                del standings_window

        elif teamstats_link:
            teamstats_data = nba_api.get_teamstats(teamstats_link)
            if len(teamstats_data) > 0:
                teamstats_window = teamstats.Stats()
                teamstats_window.setup(teamstats_data)
                teamstats_window.doModal()
                del teamstats_window
            else:
                nodata(game_obj)

        #Highlight Clips
        #Displays highlight clips of specific game
        elif highlights_link:
            h_list = nba_api.get_highlights(highlights_link)
            if len(h_list) > 0:
                nba_api.display_highlights(h_list)
            else:
                nodata(game_obj)

        #Play-By-Play Window
        elif playbyplay_link:
            #############The following link is for testing only####################
            #playbyplay_link = 'http://www.espn.com/nba/playbyplay?gameId=400975653'
            ################Remove after testing is complete#######################

            pbp_list = nba_api.get_playbyplay(playbyplay_link)
            if len(pbp_list) > 0:
                game = ast.literal_eval(game_obj)
                playbyplay_window = playbyplay.Plays(game['Title'])
                playbyplay_window.setup(pbp_list)
                playbyplay_window.doModal()
                del playbyplay_window
            else:
                nodata(game_obj)

        #Scoreboard Window
        #Activates when selecting specific game
        elif scoreboard_link:
            #############The following link is for testing only####################
            #scoreboard_link = 'http://www.espn.com/nba/boxscore?gameId=400975653'
            ################Remove after testing is complete#######################

            score_obj = nba_api.get_scoreboard(scoreboard_link)
            if len(score_obj) > 0:
                scoreboard_window = scoreboard.Score()
                scoreboard_window.setup(score_obj)
                scoreboard_window.doModal()
                del scoreboard_window
            else:
                nodata(game_obj)

        elif boxscores_link:
            #############The following link is for testing only####################
            #boxscores_link = 'http://www.espn.com/nba/boxscore?gameId=400975653'
            ################Remove after testing is complete#######################

            boxscore_obj = nba_api.get_boxscores(boxscores_link)
            if len(boxscore_obj) > 0:
                boxscore_window = boxscore.Score()
                boxscore_window.setup(boxscore_obj)
                boxscore_window.doModal()
                del boxscore_window
            else:
                nodata(game_obj)
        else:
            raise ValueError('Invalid paramstring: {0}!'.format(paramstring))
    else:
        #game_list = nba_api.get_games()
        #nba_api.display_games(game_list)
        nba_api.display_mainmenu()
Esempio n. 5
0
def router(paramstring):
    params = dict(parse_qsl(sys.argv[2][1:]))
    params.pop('sport')
    if params:
        play_me = params.get('play_me')
        league = params.get('league')
        gameId = params.get('gameId')
        endpoint = params.get('endpoint')
        game_obj = params.get('game_obj')
        title = params.get('title')
        link = params.get('link')
        data = params.get('data')
        page = params.get('page')
        #live             = params.get('checkForStream')

        #Plays selected highlight clip
        if play_me:
            play_item = xbmcgui.ListItem(path=play_me)
            xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
        elif endpoint:
            if endpoint == 'replays':
                if link:
                    replays.resolve(link, data, title)
                elif page is None:
                    from .. import checks
                    okayd = checks.checkPin()
                    if okayd is False:
                        ok = xbmcgui.Dialog().ok(
                            'Sports Guru',
                            'You need a valid pin in order to use this section of the add-on.'
                        )
                        quit()
                    replays.get_matches(league)
                else:
                    replays.get_matches(league, page)
            elif endpoint == 'today':
                game_list = soccer_api.get_games(league)
                soccer_api.display_games(game_list)
            elif endpoint == 'details':
                soccer_api.display_gameoptions(game_obj)
            elif endpoint == 'commentary':
                #gameId = '509296' #for testing
                pbp_list = soccer_api.get_playbyplay(gameId)
                if len(pbp_list) > 0:
                    game = ast.literal_eval(game_obj)
                    playbyplay_window = playbyplay.Plays(game['Title'])
                    playbyplay_window.setup(pbp_list)
                    playbyplay_window.doModal()
                    del playbyplay_window
                else:
                    nodata(game_obj)
            elif endpoint == 'h2hforms':
                #gameId = '509296' #for testing
                forms_data = soccer_api.get_h2hforms(gameId)
                forms_window = forms.Forms()
                forms_window.setup(forms_data)
                forms_window.doModal()
                del forms_window
            elif endpoint == 'lineups':
                #gameId = '491358' #for testing
                lineups = soccer_api.get_lineups(gameId)
                if len(lineups) > 0:
                    lineup_window = lineup.Players()
                    lineup_window.setup(lineups)
                    lineup_window.doModal()
                    del lineup_window
                else:
                    game = ast.literal_eval(game_obj)
                    line1 =  'The lineups for the [B]%s vs %s[/B] match aren\'t available yet. ' \
                             % (game['Abbrev1'], game['Abbrev2'])
                    line1 += 'Please check back shortly before the game begins. '
                    line1 += 'Start time is [B]%s[/B]' % game['Time']
                    xbmcgui.Dialog().ok(addonname, line1)
            elif endpoint == 'matchstats':
                stats = soccer_api.get_matchstats(gameId)
                if len(stats) > 0:
                    matchstats_window = matchstats.Match()
                    matchstats_window.setup(stats)
                    matchstats_window.doModal()
                    del matchstats_window
                else:
                    nodata(game_obj)
            elif endpoint == 'highlights':
                #gameId = '480579' #for testing
                highlights = soccer_api.get_highlights(gameId)
                if len(highlights) > 0:
                    soccer_api.display_highlights(highlights)
                else:
                    nodata(game_obj)
            elif endpoint == 'standings':
                standings_list = soccer_api.get_standings(league)
                standings_window = standings.Score()
                standings_window.setup(standings_list)
                standings_window.doModal()
                del standings_window
        elif league:
            #game_list = soccer_api.get_games(league)
            #soccer_api.display_games(game_list)
            soccer_api.display_mainmenu(league)
        else:
            raise ValueError('Invalid paramstring: {0}!'.format(paramstring))
    else:
        soccer_api.display_leagues()