Skip to content

Commit e7b02d6

Browse files
committed
Remove intermediate class and make use of kwargs.
1 parent 1b6fd03 commit e7b02d6

File tree

1 file changed

+28
-41
lines changed

1 file changed

+28
-41
lines changed

axelrod/strategies/lookerup.py

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,20 @@ class LookerUp(Player):
9292
'manipulates_state': False
9393
}
9494

95-
def __init__(self, lookup_table=None, initial_actions=None):
95+
def __init__(self, lookup_table=None, initial_actions=None,
96+
lookup_pattern=None, parameters=None):
9697
"""
9798
If no lookup table is provided to the constructor, then use the TFT one.
9899
"""
99100
super().__init__()
100101

102+
if lookup_pattern is not None:
103+
plays, op_plays, op_start_plays = parameters
104+
lookup_table = create_lookup_table_from_pattern(plays,
105+
op_plays,
106+
op_start_plays,
107+
pattern=lookup_pattern)
108+
101109
if not lookup_table:
102110
lookup_table = {
103111
('', 'C', 'D'): D,
@@ -158,77 +166,56 @@ def strategy(self, opponent):
158166
return action
159167

160168

161-
class LookerUpFromPattern(LookerUp):
162-
"""
163-
An intermediate class to create a Looker Up player from a pattern.
164-
165-
This class is not intended to be used but by default corresponds to TfT.
166-
167-
Names:
168-
- Looker Up From Patter: Original name by Vince Knight
169-
"""
170-
name = "Looker Up From Pattern"
171-
pattern = 'CDCD'
172-
parameters = (1, 1, 0)
173-
initial_actions = (C,)
174-
175-
def __init__(self):
176-
plays, op_plays, op_start_plays = self.parameters
177-
lookup_table = create_lookup_table_from_pattern(plays,
178-
op_plays,
179-
op_start_plays,
180-
pattern=self.pattern)
181-
super().__init__(lookup_table=lookup_table,
182-
initial_actions=self.initial_actions)
183-
184-
185-
class EvolvedLookerUp1_1_1(LookerUpFromPattern):
169+
class EvolvedLookerUp1_1_1(LookerUp):
186170
"""
187171
A 1 1 1 Lookerup trained with an evolutionary algorithm.
188172
189173
Names:
190174
- Evolved Lookerup 1 1 1: Original name by Marc Harper
191175
"""
192176
name = "EvolvedLookerUp1_1_1"
193-
pattern = 'CDDDDDCD'
194-
parameters = (1, 1, 1)
195-
initial_actions = (C,)
177+
def __init__(self):
178+
super().__init__(parameters=(1, 1, 1), lookup_pattern='CDDDDDCD',
179+
initial_actions=(C,))
196180

197181

198-
class EvolvedLookerUp2_2_2(LookerUpFromPattern):
182+
class EvolvedLookerUp2_2_2(LookerUp):
199183
"""
200184
A 2 2 2 Lookerup trained with an evolutionary algorithm.
201185
202186
Names:
203187
- Evolved Lookerup 2 2 2: Original name by Marc Harper
204188
"""
205189
name = "EvolvedLookerUp2_2_2"
206-
pattern = 'CDCCDCCCDCDDDCCCDCDDDDDDDCDDDCDCDDDDCCDCCCCDDDDCCDDDDCCDCDDDDDDD'
207-
parameters = (2, 2, 2)
208-
initial_actions = (C, C)
190+
def __init__(self):
191+
pattern = 'CDCCDCCCDCDDDCCCDCDDDDDDDCDDDCDCDDDDCCDCCCCDDDDCCDDDDCCDCDDDDDDD'
192+
super().__init__(parameters=(2, 2, 2), lookup_pattern=pattern,
193+
initial_actions=(C, C))
209194

210195

211-
class Winner12(LookerUpFromPattern):
196+
class Winner12(LookerUp):
212197
"""
213198
A lookup table based strategy.
214199
215200
Names:
216201
- Winner12 [Mathieu2015]_
217202
"""
218203
name = "Winner12"
219-
pattern = 'CDCDDCDD'
220-
parameters = (1, 2, 0)
221-
initial_actions = (C, C)
204+
def __init__(self):
205+
pattern = 'CDCDDCDD'
206+
super().__init__(parameters=(1, 2, 0), lookup_pattern=pattern,
207+
initial_actions=(C, C))
222208

223209

224-
class Winner21(LookerUpFromPattern):
210+
class Winner21(LookerUp):
225211
"""
226212
A lookup table based strategy.
227213
228214
Names:
229215
- Winner21 [Mathieu2015]_
230216
"""
231217
name = "Winner21"
232-
pattern = 'CDCDCDDD'
233-
parameters = (1, 2, 0)
234-
initial_actions = (D, C)
218+
def __init__(self):
219+
pattern = 'CDCDCDDD'
220+
super().__init__(parameters=(1, 2, 0), lookup_pattern=pattern,
221+
initial_actions=(D, C))

0 commit comments

Comments
 (0)