Beispiel #1
0
def find_nash_equilibrium(score_lookup):
    modified_score_lookup = remove_guaranteed_opponent_moves(score_lookup)
    if not modified_score_lookup:
        modified_score_lookup = score_lookup

    df = pd.Series(modified_score_lookup).unstack()

    equilibria = find_all_equilibria(df)
    best_eq, score = find_best_nash_equilibrium(equilibria, df)
    bot_percentages = best_eq[0]
    opponent_percentages = best_eq[1]

    bot_choices = df.index
    opponent_choices = df.columns

    return bot_choices, opponent_choices, bot_percentages, opponent_percentages, score
Beispiel #2
0
    def pick_aggresive(self, score_lookup):
        # Helper function that gets rid of moves that have no option
        modified_score_lookup = remove_guaranteed_opponent_moves(score_lookup)
        if not modified_score_lookup:
            modified_score_lookup = score_lookup
        worst_case = defaultdict(lambda: (tuple(), float('-inf')))

        logger.debug(f"\nModified Scores: {modified_score_lookup}")

        # Simply selects the highest scoring move
        for move_pair, result in modified_score_lookup.items():
            if worst_case[move_pair[0]][1] < result:
                worst_case[move_pair[0]] = move_pair, result

        aggresive = max(worst_case, key=lambda x: worst_case[x][1])

        logger.debug(f"Worst case: {worst_case})")
        return worst_case[aggresive]
Beispiel #3
0
    def pick_safest(self, score_lookup):
        # Helper function that gets rid of moves that have no option
        modified_score_lookup = remove_guaranteed_opponent_moves(score_lookup)
        if not modified_score_lookup:
            modified_score_lookup = score_lookup
        worst_case = defaultdict(lambda: (tuple(), float('inf')))

        logger.debug(f"\nModified Scores: {modified_score_lookup}")

        # Pick move that that minimizes the maxmimum loss
        for move_pair, result in modified_score_lookup.items():
            if worst_case[move_pair[0]][1] > result:
                worst_case[move_pair[0]] = move_pair, result

        safest = max(worst_case, key=lambda x: worst_case[x][1])

        logger.debug(f"Worst case: {worst_case})")
        return worst_case[safest]