Beispiel #1
0
def look_ahead(player_1, player_2, game, rounds=10):
    """Looks ahead for `rounds` and selects the next strategy appropriately."""
    results = []

    # Simulate plays for `rounds` rounds
    strategies = [C, D]
    for strategy in strategies:
        opponent_ = copy.deepcopy(player_2)  # need deepcopy here
        round_robin = RoundRobin(players=[player_1, opponent_], game=game, turns=rounds)
        simulate_match(player_1, opponent_, strategy, rounds)
        results.append(round_robin._calculate_scores(player_1, opponent_)[0])

        # Restore histories and counts
        roll_back_history(player_1, rounds)

    return strategies[results.index(max(results))]
def look_ahead(player_1, player_2, game, rounds=10):
    """Looks ahead for `rounds` and selects the next strategy appropriately."""
    results = []

    # Simulate plays for `rounds` rounds
    strategies = [C, D]
    for strategy in strategies:
        opponent_ = copy.deepcopy(player_2)  # need deepcopy here
        round_robin = RoundRobin(players=[player_1, opponent_],
                                 game=game,
                                 turns=rounds)
        simulate_match(player_1, opponent_, strategy, rounds)
        results.append(round_robin._calculate_scores(player_1, opponent_)[0])

        # Restore histories and counts
        roll_back_history(player_1, rounds)

    return strategies[results.index(max(results))]