def runGame_get_position_percentages(playerList, num_games=NUM_GAMES): spec7 = Spectacular7() # playerList = ['a', 'b', 'c','d','e','f','g','h'] WPSData = {} # start_time = time.time() # num_games = NUM_GAMES posns = [0, 0, 0, 0, 0, 0, 0, 0] for p in playerList: WPSData[p] = deepcopy(posns) # WPSData = {'a':posns[:],'b':posns[:],'c':posns[:],'d':posns[:],'e':posns[:],'f':posns,'g':posns[:],'h':posns[:]} for n in range(num_games): myGame = GameController(playerList, spec7) posList, gameStats = myGame.play_game() # Add to the Win Place Show Data table after each game for position, players in posList.items(): for player in players: WPSData[player][position - 1] += 1 # Print results # for player,position_totals in sorted(WPSData.items()): # print player,position_totals # [0], position_totals[1], position_totals[2] # print "To run %.0f games took %.2f minutes" %(num_games,(time.time() - start_time)/60 ) print WPSData return WPSData
def runGame_get_points_won_percentages(playerList): WPSData = {} spec7 = Spectacular7() # playerList = ['h', 'b', 'c','d','e','f','g','a'] start_time = time.time() num_games = NUM_GAMES stats = [0, 0, 0] posns = [stats[:], stats[:], stats[:], stats[:], stats[:], stats[:], stats[:], stats[:]] # posns = stats[:] for p in playerList: WPSData[p] = deepcopy(posns) # WPSData = {'a':deepcopy(posns),'b':deepcopy(posns),'c':deepcopy(posns),'d':deepcopy(posns),'e':deepcopy(posns),'f':deepcopy(posns),'g':deepcopy(posns),'h':deepcopy(posns)} # print WPSData # WPSData = {'a':deepcopy(posns),'b':deepcopy(posns),'c':deepcopy(posns),'d':deepcopy(posns),'e':deepcopy(posns),'f':deepcopy(posns),'g':deepcopy(posns),'h':deepcopy(posns)} for n in range(num_games): # playerList = ['a', 'b', 'c','d','e','f','g','h'] myGame = GameController(playerList, spec7) posList, gameStats = myGame.play_game() # print gameStats # print posList for position, players in posList.items(): for p in players: WPSData[p][position - 1][0] += 1 WPSData[p][position - 1][1] += gameStats[p][0] WPSData[p][position - 1][2] += gameStats[p][1] for k in sorted(WPSData.keys()): print k, WPSData[k] print "To run %.0f games took %.2f minutes" % (num_games, (time.time() - start_time) / 60)
def runGame_get_WPS_frequencies(playerList, pwin_dict, num_games=NUM_GAMES): """ Returns a dictionary that looks like {'123':300,'124':80 ...} for all 336 combinations """ spec7 = Spectacular7() WPS_freqs = {} def xuniqueCombinations(items, n): if n == 0: yield [] else: for i in xrange(len(items)): for cc in xuniqueCombinations(items[i + 1 :], n - 1): yield [items[i]] + cc def xcombinations(items, n): if n == 0: yield [] else: for i in xrange(len(items)): for cc in xcombinations(items[:i] + items[i + 1 :], n - 1): yield [items[i]] + cc l = list(xcombinations(["1", "2", "3", "4", "5", "6", "7", "8"], 3)) for i in l: permut = "".join(i) WPS_freqs[permut] = 0 # print len(WPS_freqs) for n in range(num_games): myGame = GameController(playerList, spec7, pwin_dict) posList, gameStats = myGame.play_game() # Add to the Win Place Show Data table after each game # print posList # Need to look at player list - get original post position # print posList[1] # print playerList pos1 = playerList.index(posList[1][0]) + 1 pos2 = playerList.index(posList[2][0]) + 1 pos3 = playerList.index(posList[3][0]) + 1 k = str(pos1) + str(pos2) + str(pos3) WPS_freqs[k] += 1 # print k # print WPS_freqs return WPS_freqs
def runGame_get_WPSL_percentages(playerList, num_games=NUM_GAMES): spec7 = Spectacular7() # playerList = ['a', 'b', 'c','d','e','f','g','h'] WPSData = {} # start_time = time.time() # num_games = NUM_GAMES posns = [0, 0, 0, 0, 0, 0, 0, 0] for p in playerList: WPSData[p] = deepcopy(posns) # WPSData = {'a':posns[:],'b':posns[:],'c':posns[:],'d':posns[:],'e':posns[:],'f':posns,'g':posns[:],'h':posns[:]} for n in range(num_games): myGame = GameController(playerList, spec7) posList, gameStats = myGame.play_game() # Add to the Win Place Show Data table after each game for position, players in posList.items(): for player in players: WPSData[player][position - 1] += 1 # Now condition Data into WPSL % ages by dividing each by num_games WPSL_percentages = [] WPSL_player_percentages = {} # for p in playerList: # d = WPSL_player_percentages[p] # WPSL_percentages.append(d) for player, position_totals in WPSData.items(): WPSL_player_percentages = {} # print player, position_totals, percentages = [(float(x) / num_games) for x in position_totals] fin_percentages = percentages[0:3] fin_percentages.append(1 - sum(fin_percentages[:])) # for d in WPSL_percentages: # if player in d.keys(): # d[player] = fin_percentages WPSL_player_percentages[player] = fin_percentages WPSL_percentages.append(WPSL_player_percentages) # print fin_percentages # print WPSL_percentages return WPSL_percentages