def pickup(state): """ Recommends players to pick up to win the match of the week :param state: current state of variables :return: prints the best pick up for the week """ # Initialize variables if state.opponent is None: while 1: state.opponent = raw_input("Who are you playing this week?: ") if state.opponent not in state.teams: print "Please enter a valid opponent name\n" else: break taken_players = [] for users in state.teams: state.teams[users] = Helper.lowercase(state.teams[users]) taken_players += state.teams[users] players_on_team = Helper.lowercase(state.teams[state.current_user]) swap_dictionary = defaultdict(lambda: defaultdict(int)) # Constructs a list of players from best to worst ranked_players = Helper.sort_dictionary(state.cumulative_player_statistics[state.iteration]) ranked_players = [ranked_players[x][0] for x in range(len(ranked_players))] for n in range(len(ranked_players)): # Removes players already on the team if ranked_players[n] in players_on_team: players_on_team.pop(players_on_team.index(ranked_players[n])) # Prints other players if ranked_players[n] not in taken_players and len(players_on_team) != 0: # Determines the best player to drop and add for player in players_on_team: new_change = sum(Helper.evaluate_player_swap(copy.deepcopy(state.teams), player, ranked_players[n], state.normalized_player_statistics[state.iteration], state, state.opponent)[0].values()) swap_dictionary[player][ranked_players[n]] = new_change return swap_dictionary
def sort_players(self, cum_stats): self.sorted_players = Helper.sort_dictionary(cum_stats)