diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index bc80eeccc..d800aa46c 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -284,6 +284,7 @@ ZDMischief, ZDSet2, ) +from .schwoba_sen_gnitz import SchwobaSenGnitz # Note: Meta* strategies are handled in .__init__.py @@ -438,6 +439,7 @@ RevisedDowning, Ripoff, RiskyQLearner, + SchwobaSenGnitz, SecondByAppold, SecondByBlack, SecondByBorufsen, diff --git a/axelrod/strategies/schwoba_sen_gnitz.py b/axelrod/strategies/schwoba_sen_gnitz.py new file mode 100644 index 000000000..867b40dfb --- /dev/null +++ b/axelrod/strategies/schwoba_sen_gnitz.py @@ -0,0 +1,62 @@ +import random +from typing import List, Dict, Any +from axelrod.action import Action +from axelrod.player import Player + + +class SchwobaSenGnitz(Player): + """Schwoba sen gnitz.""" + + name: str = "schwoba sen gnitz" + authors: List[str] = ["Georg 'HackyHackberger' Schmidt"] + classifier: Dict[str, Any] = { + "memory_depth": float("inf"), + "stochastic": True, + "makes_use_of": set(), + "long_run_time": False, + "inspects_source": False, + "manipulates_state": False, + "manipulates_history": False, + "uses_length": False, + "uses_game": False, + "uses_tournament": False, + "uses_clones": False, + } + + def __init__(self) -> None: + super().__init__() + self.raubtier_erwacht = False + self.schutz_modus_aktiviert = False + + def strategy(self, opponent: Player) -> Action: + runde = len(self.history) + if runde == 0: + return Action.C + + if not opponent.history: + return Action.C + + if not self.raubtier_erwacht and opponent.history[-1] == Action.D: + self.raubtier_erwacht = True + + if not self.raubtier_erwacht: + return Action.C + + if runde >= 10 and len(opponent.history) >= 10: + letzte_10_gegner = opponent.history[-10:] + if all(zug == Action.D for zug in letzte_10_gegner): + self.schutz_modus_aktiviert = True + + if self.schutz_modus_aktiviert: + return Action.D + + if opponent.history[-1] == Action.D: + if random.random() < 0.897: + return Action.C + else: + return Action.D + + if random.random() < 0.102: + return Action.D + + return Action.C diff --git a/axelrod/tests/unit/test_schwoba_sen_gnitz.py b/axelrod/tests/unit/test_schwoba_sen_gnitz.py new file mode 100644 index 000000000..8d2d8ded9 --- /dev/null +++ b/axelrod/tests/unit/test_schwoba_sen_gnitz.py @@ -0,0 +1,25 @@ +import axelrod as axl +from axelrod.action import Action +from axelrod.strategies.schwoba_sen_gnitz import SchwobaSenGnitz + + +class TestSchwoba_Sen_Gnitz(axl.TestPlayer): + name = "schwoba sen gnitz" + player = SchwobaSenGnitz + + def test_strategy_initial_cooperation(self): + self.versus_test( + axl.Cooperator, expected_actions=[(Action.C, Action.C)] * 5 + ) + + def test_schutz_modus(self): + player = self.player() + opponent = axl.Defector() + + for _ in range(10): + player.play(opponent) + + self.assertEqual(player.strategy(opponent), Action.D) + + player.play(opponent) + self.assertEqual(player.strategy(opponent), Action.D)