Exemplo n.º 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))]
Exemplo n.º 2
0
    def look_ahead(self, opponent, rounds = 10):
        """Plays a number of rounds to determine the best strategy."""
        results = []
        game = Game()
        round_robin = RoundRobin(players=[self, opponent], game=game, turns=rounds)
        strategies = ['C', 'D']

        dummy_history_self = copy.copy(self.history)
        dummy_history_opponent = copy.copy(opponent.history)

        for strategy in strategies:
            self.simulate_match(opponent, strategy, rounds)
            results.append(round_robin.calculate_scores(self, opponent)[0])

            self.history = copy.copy(dummy_history_self)
            opponent.history = copy.copy(dummy_history_opponent)

        return strategies[results.index(max(results))]
Exemplo n.º 3
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(self, opponent, rounds=10):
        """Plays a number of rounds to determine the best strategy."""
        results = []
        game = Game()
        round_robin = RoundRobin(players=[self, opponent],
                                 game=game,
                                 turns=rounds)
        strategies = ['C', 'D']

        dummy_history_self = copy.copy(self.history)
        dummy_history_opponent = copy.copy(opponent.history)

        for strategy in strategies:
            self.simulate_match(opponent, strategy, rounds)
            results.append(round_robin.calculate_scores(self, opponent)[0])

            self.history = copy.copy(dummy_history_self)
            opponent.history = copy.copy(dummy_history_opponent)

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