Skip to content

Commit

Permalink
Format code with black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwonmoon committed Jan 23, 2025
1 parent 47d8a06 commit 6c20f54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 42 deletions.
2 changes: 1 addition & 1 deletion axelrod/strategies/momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Momentum(Player):
def __init__(
self,
alpha=0.9914655399877477, # Optimized by Genetic Algorithm. You can try to adapt it to any Env.
threshold=0.9676595613724907, # This one too
threshold=0.9676595613724907, # This one too
) -> None:
super().__init__()
self.alpha = alpha
Expand Down
71 changes: 30 additions & 41 deletions axelrod/tests/strategies/test_momentum.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import axelrod as axl
from axelrod import Action
from axelrod.tests.strategies.test_player import TestPlayer
from axelrod.strategies.momentum import Momentum
from axelrod.tests.strategies.test_player import TestPlayer

C, D = Action.C, Action.D


class TestMomentum(TestPlayer):
name = "Momentum"
player = Momentum
Expand Down Expand Up @@ -32,68 +33,56 @@ def test_strategy(self):
self.versus_test(
axl.MockPlayer(actions=[C]),
expected_actions=actions,
init_kwargs={"alpha": 0.5,
"threshold": 0.5
},
attrs={"momentum": 1.0}
init_kwargs={"alpha": 0.5, "threshold": 0.5},
attrs={"momentum": 1.0},
)

actions = [(C, D), (C, D), (D, D)]
self.versus_test(
axl.MockPlayer(actions=[D]),
expected_actions=actions,
init_kwargs={"alpha": 0.5,
"threshold": 0.5
},
attrs={"momentum": 0.25}
init_kwargs={"alpha": 0.5, "threshold": 0.5},
attrs={"momentum": 0.25},
)

def test_vs_alternator(self):
actions = [(C, C), (C, D), (C, C), (C, D), (D, C)]
self.versus_test(axl.Alternator(),
expected_actions=actions,
init_kwargs={"alpha": 0.5,
"threshold": 0.5
},
self.versus_test(
axl.Alternator(),
expected_actions=actions,
init_kwargs={"alpha": 0.5, "threshold": 0.5},
)

def test_vs_cooperator(self):
actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
self.versus_test(axl.Cooperator(),
expected_actions=actions,
init_kwargs={"alpha": 0.5,
"threshold": 0.5
},
self.versus_test(
axl.Cooperator(),
expected_actions=actions,
init_kwargs={"alpha": 0.5, "threshold": 0.5},
)

def test_vs_defector(self):
actions = [(C, D), (C, D), (D, D), (D, D), (D, D)]
self.versus_test(axl.Defector(),
expected_actions=actions,
init_kwargs={"alpha": 0.5,
"threshold": 0.5
},
self.versus_test(
axl.Defector(),
expected_actions=actions,
init_kwargs={"alpha": 0.5, "threshold": 0.5},
)

def test_vs_random(self):
# We can also test against random strategies
actions = [(C, D), (C, C), (C, C), (C, D), (D, D)]
self.versus_test(axl.Random(),
expected_actions=actions,
seed=17,
init_kwargs={"alpha": 0.5,
"threshold": 0.5
},
self.versus_test(
axl.Random(),
expected_actions=actions,
seed=17,
init_kwargs={"alpha": 0.5, "threshold": 0.5},
)

def test_vs_random2(self):
actions = [(C, C), (C, C), (C, C), (C, C)]
self.versus_test(axl.Random(),
expected_actions=actions,
seed=3,
init_kwargs={"alpha": 0.5,
"threshold": 0.5
},
self.versus_test(
axl.Random(),
expected_actions=actions,
seed=3,
init_kwargs={"alpha": 0.5, "threshold": 0.5},
)


0 comments on commit 6c20f54

Please sign in to comment.