Skip to content

Add type hints to mock-player #834

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

Merged
merged 3 commits into from
Feb 1, 2017
Merged
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
10 changes: 7 additions & 3 deletions axelrod/mock_player.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import warnings
from axelrod import Actions, Player, update_history, update_state_distribution
from axelrod.actions import Action
from collections import defaultdict

from typing import List, Tuple

C, D = Actions.C, Actions.D

Expand All @@ -12,7 +16,7 @@ class MockPlayer(Player):

name = "Mock Player"

def __init__(self, actions=None, history=None, state_dist=None):
def __init__(self, actions: List[Action] =None, history: List[Action] =None, state_dist: defaultdict =None) -> None:
# Need to retain history for opponents that examine opponents history
# Do a deep copy just to be safe
super().__init__()
Expand All @@ -28,7 +32,7 @@ def __init__(self, actions=None, history=None, state_dist=None):
else:
self.actions = []

def strategy(self, opponent):
def strategy(self, opponent: Player) -> Action:
# Return the next saved action, if present.
try:
action = self.actions.pop(0)
Expand All @@ -37,7 +41,7 @@ def strategy(self, opponent):
return C


def simulate_play(player1, player2, action1=None, action2=None):
def simulate_play(player1: Player, player2: Player, action1: Action =None, action2: Action =None) -> Tuple[Action, Action]:
"""
Simulates play with or without forced history. If action1 and action2 are given, these
actions are enforced in the players strategy. This generally should not be
Expand Down