Ejemplo n.º 1
0
    def strategy(self, opponent: Player) -> Action:
        """
        Pretends to play the opponent a number of times before each match.
        The primary purpose is to look far enough ahead to see if a defect will
        be punished by the opponent.
        """
        game = self.match_attributes["game"]

        best_strategy = look_ahead(self, opponent, game)

        return best_strategy
Ejemplo n.º 2
0
    def strategy(self, opponent: Player) -> Action:
        """Pretends to play the opponent a number of times before each match.
        The primary purpose is to look far enough ahead to see if a defect will
        be punished by the opponent.

        If the MindReader attempts to play itself (or another similar
        strategy), then it will cause a recursion loop, so this is also handled
        in this method, by defecting if the method is called by strategy
        """

        curframe = inspect.currentframe()
        calframe = inspect.getouterframes(curframe, 2)
        calname = calframe[1][3]

        if calname in ('strategy', 'simulate_match'):
            return D

        game = self.match_attributes["game"]

        best_strategy = look_ahead(self, opponent, game)

        return best_strategy
Ejemplo n.º 3
0
    def strategy(self, opponent):
        """Pretends to play the opponent a number of times before each match.
        The primary purpose is to look far enough ahead to see if a defect will
        be punished by the opponent.

        If the MindReader attempts to play itself (or another similar
        strategy), then it will cause a recursion loop, so this is also handled
        in this method, by defecting if the method is called by strategy
        """

        curframe = inspect.currentframe()
        calframe = inspect.getouterframes(curframe, 2)
        calname = calframe[1][3]

        if calname in ('strategy', 'simulate_match'):
            return D

        game = self.match_attributes["game"]

        best_strategy = look_ahead(self, opponent, game)

        return best_strategy
Ejemplo n.º 4
0
 def test_tit_for_tat(self):
     tft = axelrod.TitForTat()
     # Cooperation should be chosen if we look ahead further than one move.
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 1), D)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 2), C)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 5), C)
Ejemplo n.º 5
0
 def test_cooperator(self):
     tft = axelrod.Cooperator()
     # It always makes sense to defect here.
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 1), D)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 2), D)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 5), D)
Ejemplo n.º 6
0
 def test_tit_for_tat(self):
     tft = axelrod.TitForTat()
     # Cooperation should be chosen if we look ahead further than one move.
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 1), D)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 2), C)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 5), C)
Ejemplo n.º 7
0
 def test_cooperator(self):
     tft = axelrod.Cooperator()
     # It always makes sense to defect here.
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 1), D)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 2), D)
     self.assertEqual(look_ahead(self.inspector, tft, self.game, 5), D)