예제 #1
0
    def build_wins(self):
        """
        Returns:
        --------

            The total wins per player for each repetition lengths.
            List of the form:

            [ML1, ML2, ML3..., MLn]

            Where n is the number of players and MLi is a list of the form:

            [pi1, pi2, pi3, ..., pim]

            Where m is the number of repetitions and pij is the total wins
            obtained by each player in repetition j.

            In Axelrod's original tournament, there were no self-interactions
            (e.g. player 1 versus player 1) and so these are also ignored.
        """
        wins = [[0 for rep in range(self.nrepetitions)]
                for _ in range(self.nplayers)]

        for index_pair, repetitions in self.interactions.items():
            if index_pair[0] != index_pair[1]:  # Ignore self interactions
                for player in range(2):
                    player_index = index_pair[player]

                    for rep, interaction in enumerate(repetitions):
                        winner_index = iu.compute_winner_index(
                            interaction, self.game)
                        if winner_index is not False and player == winner_index:
                            wins[player_index][rep] += 1

        return wins
예제 #2
0
파일: result_set.py 프로젝트: 314pe/Axelrod
    def build_wins(self):
        """
        Returns:
        --------

            The total wins per player for each repetition lengths.
            List of the form:

            [ML1, ML2, ML3..., MLn]

            Where n is the number of players and MLi is a list of the form:

            [pi1, pi2, pi3, ..., pim]

            Where m is the number of repetitions and pij is the total wins
            obtained by each player in repetition j.

            In Axelrod's original tournament, there were no self-interactions
            (e.g. player 1 versus player 1) and so these are also ignored.
        """
        wins = [[0 for rep in range(self.nrepetitions)] for _ in
                range(self.nplayers)]

        for index_pair, repetitions in self.interactions.items():
            if index_pair[0] != index_pair[1]:  # Ignore self interactions
                for player in range(2):
                    player_index = index_pair[player]

                    for rep, interaction in enumerate(repetitions):
                        winner_index = iu.compute_winner_index(interaction)
                        if winner_index is not False and player == winner_index:
                            wins[player_index][rep] += 1

        return wins
예제 #3
0
 def _update_wins(self, repetition, p1, p2, interaction):
     match_winner_index = iu.compute_winner_index(interaction,
                                                  game=self.game)
     index_pair = [p1, p2]
     if match_winner_index is not False:
         winner_index = index_pair[match_winner_index]
         self.wins[winner_index][repetition] += 1
예제 #4
0
파일: match.py 프로젝트: tscizzle/Axelrod
 def winner(self):
     """Returns the winner of the Match"""
     winner_index = iu.compute_winner_index(self.result, self.game)
     if winner_index is False:  # No winner
         return False
     if winner_index is None:  # No plays
         return None
     return self.players[winner_index]
예제 #5
0
파일: match.py 프로젝트: tscizzle/Axelrod
 def winner(self):
     """Returns the winner of the Match"""
     winner_index = iu.compute_winner_index(self.result, self.game)
     if winner_index is False:  # No winner
         return False
     if winner_index is None:  # No plays
         return None
     return self.players[winner_index]
예제 #6
0
    def _update_wins(self, repetition, p1, p2, interaction):
        """
        During a read of the data, update the wins attribute

        Parameters
        ----------

            repetition : int
                The index of a repetition
            p1, p2 : int
                The indices of the first and second player
            interaction : list of tuples
                A list of interactions
        """
        match_winner_index = iu.compute_winner_index(interaction,
                                                     game=self.game)
        index_pair = [p1, p2]
        if match_winner_index is not False:
            winner_index = index_pair[match_winner_index]
            self.wins[winner_index][repetition] += 1
예제 #7
0
    def _update_wins(self, repetition, p1, p2, interaction):
        """
        During a read of the data, update the wins attribute

        Parameters
        ----------

            repetition : int
                The index of a repetition
            p1, p2 : int
                The indices of the first and second player
            interaction : list of tuples
                A list of interactions
        """
        match_winner_index = iu.compute_winner_index(interaction,
                                                     game=self.game)
        index_pair = [p1, p2]
        if match_winner_index is not False:
            winner_index = index_pair[match_winner_index]
            self.wins[winner_index][repetition] += 1
예제 #8
0
    def _calculate_results(self, interactions):
        results = []

        scores = iu.compute_final_score(interactions, self.game)
        results.append(scores)

        score_diffs = scores[0] - scores[1], scores[1] - scores[0]
        results.append(score_diffs)

        turns = len(interactions)
        results.append(turns)

        score_per_turns = iu.compute_final_score_per_turn(
            interactions, self.game)
        results.append(score_per_turns)

        score_diffs_per_turns = score_diffs[0] / turns, score_diffs[1] / turns
        results.append(score_diffs_per_turns)

        initial_coops = tuple(
            map(bool, iu.compute_cooperations(interactions[:1])))
        results.append(initial_coops)

        cooperations = iu.compute_cooperations(interactions)
        results.append(cooperations)

        state_distribution = iu.compute_state_distribution(interactions)
        results.append(state_distribution)

        state_to_action_distributions = iu.compute_state_to_action_distribution(
            interactions)
        results.append(state_to_action_distributions)

        winner_index = iu.compute_winner_index(interactions, self.game)
        results.append(winner_index)

        return results
예제 #9
0
    def _calculate_results(self, interactions):
        results = []

        scores = iu.compute_final_score(interactions, self.game)
        results.append(scores)

        score_diffs = scores[0] - scores[1], scores[1] - scores[0]
        results.append(score_diffs)

        turns = len(interactions)
        results.append(turns)

        score_per_turns = iu.compute_final_score_per_turn(interactions, self.game)
        results.append(score_per_turns)

        score_diffs_per_turns = score_diffs[0] / turns, score_diffs[1] / turns
        results.append(score_diffs_per_turns)

        initial_coops = tuple(map(bool, iu.compute_cooperations(interactions[:1])))
        results.append(initial_coops)

        cooperations = iu.compute_cooperations(interactions)
        results.append(cooperations)

        state_distribution = iu.compute_state_distribution(interactions)
        results.append(state_distribution)

        state_to_action_distributions = iu.compute_state_to_action_distribution(
            interactions
        )
        results.append(state_to_action_distributions)

        winner_index = iu.compute_winner_index(interactions, self.game)
        results.append(winner_index)

        return results
예제 #10
0
 def test_compute_winner_index(self):
     for inter, winner in zip(self.interactions, self.winners):
         self.assertEqual(winner, iu.compute_winner_index(inter))
예제 #11
0
 def test_compute_winner_index(self):
     for inter, winner in zip(self.interactions, self.winners):
         self.assertEqual(winner, iu.compute_winner_index(inter))