Exemplo n.º 1
0
    def test_strategies_without_countermeasures_return_their_strategy(self):
        tft = axelrod.TitForTat()
        inspector = axelrod.Alternator()

        tft.play(inspector)
        self.assertEqual(tft.history, [C])
        self.assertEqual(inspect_strategy(inspector=inspector, opponent=tft), C)
        tft.play(inspector)
        self.assertEqual(tft.history, [C, C])
        self.assertEqual(inspect_strategy(inspector=inspector, opponent=tft), D)
        self.assertEqual(tft.strategy(inspector), D)
Exemplo n.º 2
0
    def test_strategies_without_countermeasures_return_their_strategy(self):
        tft = axelrod.TitForTat()
        inspector = axelrod.Alternator()

        tft.play(inspector)
        self.assertEqual(tft.history, [C])
        self.assertEqual(inspect_strategy(inspector=inspector, opponent=tft), C)
        tft.play(inspector)
        self.assertEqual(tft.history, [C, C])
        self.assertEqual(inspect_strategy(inspector=inspector, opponent=tft), D)
        self.assertEqual(tft.strategy(inspector), D)
Exemplo n.º 3
0
    def test_strategies_without_countermeasures_return_their_strategy(self):
        tft = axl.TitForTat()
        inspector = axl.Alternator()
        match = axl.Match((tft, inspector), turns=1)
        match.play()
        self.assertEqual(tft.history, [C])
        self.assertEqual(inspect_strategy(inspector=inspector, opponent=tft),
                         C)

        match = axl.Match((tft, inspector), turns=2)
        match.play()
        self.assertEqual(tft.history, [C, C])
        self.assertEqual(inspect_strategy(inspector=inspector, opponent=tft),
                         D)
        self.assertEqual(tft.strategy(inspector), D)
Exemplo n.º 4
0
    def test_strategies_with_countermeasures_return_their_countermeasures(self):
        d_geller = axelrod.GellerDefector()
        inspector = axelrod.Cooperator()
        d_geller.play(inspector)

        self.assertEqual(inspect_strategy(inspector=inspector, opponent=d_geller), D)
        self.assertEqual(d_geller.strategy(inspector), C)
Exemplo n.º 5
0
    def test_strategies_with_countermeasures_return_their_countermeasures(self):
        d_geller = axelrod.GellerDefector()
        inspector = axelrod.Cooperator()
        d_geller.play(inspector)

        self.assertEqual(inspect_strategy(inspector=inspector, opponent=d_geller), D)
        self.assertEqual(d_geller.strategy(inspector), C)
Exemplo n.º 6
0
    def strategy(self, opponent: Player) -> Action:
        """
        Look at what the opponent will play in the next round and choose a strategy
        that gives the least jail time, which is is equivalent to playing the same
        strategy as that which the opponent will play.
        """

        return inspect_strategy(self, opponent)
Exemplo n.º 7
0
    def strategy(self, opponent: Player) -> Action:
        """
        Look at what the opponent will play in the next round and choose a strategy
        that gives the least jail time, which is is equivalent to playing the same
        strategy as that which the opponent will play.
        """

        return inspect_strategy(self, opponent)
Exemplo n.º 8
0
 def test_strategies_with_countermeasures_return_their_countermeasures(
         self):
     d_geller = axl.GellerDefector()
     inspector = axl.Cooperator()
     match = axl.Match((d_geller, inspector), turns=1)
     match.play()
     self.assertEqual(
         inspect_strategy(inspector=inspector, opponent=d_geller), D)
     self.assertEqual(d_geller.strategy(inspector), C)
Exemplo n.º 9
0
 def strategy(self, opponent: Player) -> Action:
     """Will read the mind of the opponent and play the opponent's strategy. """
     return inspect_strategy(self, opponent)