Skip to content

Commit b80550c

Browse files
marcharperdrvinceknight
authored andcommitted
More PEP8 and style fixes
1 parent f80072f commit b80550c

31 files changed

+81
-72
lines changed

axelrod/deterministic_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from collections import UserDict
22
import pickle
3-
from typing import List, Tuple
43

54
from .actions import Action
65
from .player import Player
76

7+
from typing import List, Tuple
88

99
CachePlayerKey = Tuple[Player, Player, int]
1010
CacheKey = Tuple[str, str, int]

axelrod/ecosystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from axelrod.result_set import ResultSet
21
import random
2+
from axelrod.result_set import ResultSet
33
from typing import List, Callable
44

55

axelrod/fingerprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections import namedtuple
22
from tempfile import NamedTemporaryFile
33
import matplotlib.pyplot as plt
4-
from typing import List, Any, Union
54
import numpy as np
65
import tqdm
76

@@ -11,6 +10,7 @@
1110
from axelrod.interaction_utils import (
1211
compute_final_score_per_turn, read_interactions_from_file)
1312

13+
from typing import List, Any, Union
1414

1515
Point = namedtuple('Point', 'x y')
1616

axelrod/mock_player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from collections import defaultdict
22
from itertools import cycle
3-
from typing import List, Tuple
43
import warnings
54

65
from axelrod.actions import Actions, Action
76
from axelrod.player import Player, update_history, update_state_distribution
87

8+
from typing import List, Tuple
99

1010
C, D = Actions.C, Actions.D
1111

axelrod/player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import inspect
44
import itertools
55
import random
6-
import types
7-
from typing import Dict, Any
86

97
import numpy as np
108

119
from axelrod.actions import Actions, flip_action
1210
from .game import DefaultGame
1311

12+
import types
13+
from typing import Dict, Any
1414

1515
C, D = Actions.C, Actions.D
1616

axelrod/strategies/adaptive.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from axelrod.actions import Actions, Action
22
from axelrod.player import Player
3-
import axelrod
43

54
from typing import List
65

axelrod/strategies/ann.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import numpy as np
88

9-
from typing import List, Tuple
10-
119
from axelrod.actions import Actions, Action
1210
from axelrod.player import Player
1311
from axelrod.load_data_ import load_weights
1412

13+
from typing import List, Tuple
14+
1515
C, D = Actions.C, Actions.D
1616
nn_weights = load_weights()
1717

@@ -69,8 +69,6 @@ def compute_features(player: Player, opponent: Player) -> List[int]:
6969
opponent_previous2_c = 0
7070
opponent_previous2_d = 0
7171

72-
73-
7472
else:
7573
opponent_first_c = 1 if opponent.history[0] == C else 0
7674
opponent_first_d = 1 if opponent.history[0] == D else 0
@@ -179,7 +177,8 @@ class ANN(Player):
179177
'long_run_time': False
180178
}
181179

182-
def __init__(self, weights: List[float], num_features: int, num_hidden: int) -> None:
180+
def __init__(self, weights: List[float], num_features: int,
181+
num_hidden: int) -> None:
183182
super().__init__()
184183
(i2h, h2o, bias) = split_weights(weights, num_features, num_hidden)
185184
self.input_to_hidden_layer_weights = np.matrix(i2h)

axelrod/strategies/apavlov.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from axelrod.actions import Actions, Action
32
from axelrod.player import Player
43

@@ -29,7 +28,7 @@ class APavlov2006(Player):
2928

3029
def __init__(self) -> None:
3130
super().__init__()
32-
self.opponent_class = None # type: str
31+
self.opponent_class = None # type: str
3332

3433
def strategy(self, opponent: Player) -> Action:
3534
# TFT for six rounds

axelrod/strategies/axelrod_first.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from axelrod.actions import Actions, flip_action, Action
88
from axelrod.player import Player
99
from axelrod.random_ import random_choice
10-
from.memoryone import MemoryOnePlayer
1110
from axelrod.strategy_transformers import FinalTransformer
11+
from .memoryone import MemoryOnePlayer
12+
1213
from scipy.stats import chisquare
1314

1415
from typing import List, Dict, Tuple

axelrod/strategies/backstabber.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from axelrod.actions import Actions
1+
from axelrod.actions import Action, Actions
22
from axelrod.player import Player
33
from axelrod.strategy_transformers import FinalTransformer
4-
from axelrod.actions import Action
54

65
C, D = Actions.C, Actions.D
76

@@ -58,7 +57,8 @@ def strategy(self, opponent: Player) -> Action:
5857

5958
def _backstabber_strategy(opponent: Player) -> Action:
6059
"""
61-
Cooperates until opponent defects a total of four times, then always defects.
60+
Cooperates until opponent defects a total of four times, then always
61+
defects.
6262
"""
6363
if not opponent.history:
6464
return C
@@ -69,7 +69,8 @@ def _backstabber_strategy(opponent: Player) -> Action:
6969

7070
def _alt_strategy(opponent: Player) -> Action:
7171
"""
72-
If opponent's previous two plays were defect, then defects on next round. Otherwise, cooperates.
72+
If opponent's previous two plays were defect, then defects on next round.
73+
Otherwise, cooperates.
7374
"""
7475
previous_two_plays = opponent.history[-2:]
7576
if previous_two_plays == [D, D]:
@@ -79,8 +80,8 @@ def _alt_strategy(opponent: Player) -> Action:
7980

8081
def _opponent_triggers_alt_strategy(opponent: Player) -> bool:
8182
"""
82-
If opponent did not defect in first 7 rounds and the current round is from 8 to 180, return True.
83-
Else, return False.
83+
If opponent did not defect in first 7 rounds and the current round is from 8
84+
to 180, return True. Else, return False.
8485
"""
8586
before_alt_strategy = first_n_rounds = 7
8687
last_round_of_alt_strategy = 180
@@ -90,7 +91,8 @@ def _opponent_triggers_alt_strategy(opponent: Player) -> bool:
9091
return before_alt_strategy < current_round <= last_round_of_alt_strategy
9192

9293

93-
def _opponent_defected_in_first_n_rounds(opponent: Player, first_n_rounds: int) -> bool:
94+
def _opponent_defected_in_first_n_rounds(opponent: Player, first_n_rounds: int
95+
) -> bool:
9496
"""
9597
If opponent defected in the first N rounds, return True. Else return False.
9698
"""

0 commit comments

Comments
 (0)