Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints to axelrod_second, backstabber, defector #854

Merged
merged 4 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions axelrod/strategies/axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import random

from axelrod import Actions, Player, flip_action, random_choice
from axelrod.actions import Action

C, D = Actions.C, Actions.D

Expand Down Expand Up @@ -35,7 +36,7 @@ class Champion(Player):
'manipulates_state': False
}

def strategy(self, opponent):
def strategy(self, opponent: Player) -> Action:
current_round = len(self.history)
expected_length = self.match_attributes['length']
# Cooperate for the first 1/20-th of the game
Expand Down Expand Up @@ -81,7 +82,7 @@ class Eatherley(Player):
}

@staticmethod
def strategy(opponent):
def strategy(opponent: Player) -> Action:
# Cooperate on the first move
if not len(opponent.history):
return C
Expand Down Expand Up @@ -118,11 +119,11 @@ class Tester(Player):
'manipulates_state': False
}

def __init__(self):
def __init__(self) -> None:
super().__init__()
self.is_TFT = False

def strategy(self, opponent):
def strategy(self, opponent: Player) -> Action:
# Defect on the first move
if not opponent.history:
return D
Expand Down
5 changes: 3 additions & 2 deletions axelrod/strategies/backstabber.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from axelrod import Actions, Player
from axelrod.strategy_transformers import FinalTransformer
from axelrod.actions import Action

C, D = Actions.C, Actions.D

Expand All @@ -23,7 +24,7 @@ class BackStabber(Player):
}

@staticmethod
def strategy(opponent):
def strategy(opponent: Player) -> Action:
if not opponent.history:
return C
if opponent.defections > 3:
Expand Down Expand Up @@ -51,7 +52,7 @@ class DoubleCrosser(Player):
'manipulates_state': False
}

def strategy(self, opponent):
def strategy(self, opponent: Player) -> Action:
cutoff = 6

if not opponent.history:
Expand Down
5 changes: 3 additions & 2 deletions axelrod/strategies/defector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from axelrod import Actions, Player
from axelrod.actions import Action

C, D = Actions.C, Actions.D

Expand All @@ -18,7 +19,7 @@ class Defector(Player):
}

@staticmethod
def strategy(opponent):
def strategy(opponent: Player) -> Action:
return D


Expand All @@ -36,7 +37,7 @@ class TrickyDefector(Player):
'manipulates_state': False
}

def strategy(self, opponent):
def strategy(self, opponent: Player) -> Action:
"""Almost always defects, but will try to trick the opponent into
cooperating.

Expand Down
3 changes: 3 additions & 0 deletions type_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/better_an
mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/darwin.py
mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/cycler.py
mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/cooperator.py
mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/axelrod_second.py
mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/backstabber.py
mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/defector.py