Skip to content

Commit 09daa29

Browse files
committed
Refactor code to use inheritance further.
1 parent 4971d50 commit 09daa29

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

axelrod/strategies/lookerup.py

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -170,71 +170,54 @@ class EvolvedLookerUp1_1_1(LookerUp):
170170
- Evolved Lookerup 1 1 1: Original name by Marc Harper
171171
"""
172172
name = "EvolvedLookerUp1_1_1"
173+
pattern = 'CDDDDDCD'
174+
parameters = (1, 1, 1)
175+
initial_actions = (C,)
173176

174177
def __init__(self):
175-
pattern = 'CDDDDDCD'
176-
lookup_table = create_lookup_table_from_pattern(plays=1,
177-
op_plays=1,
178-
op_start_plays=1,
179-
pattern=pattern)
178+
plays, op_plays, op_start_plays = self.parameters
179+
lookup_table = create_lookup_table_from_pattern(plays,
180+
op_plays,
181+
op_start_plays,
182+
pattern=self.pattern)
180183
super().__init__(lookup_table=lookup_table,
181-
initial_actions=(C,))
184+
initial_actions=self.initial_actions)
182185

183186

184-
class EvolvedLookerUp2_2_2(LookerUp):
187+
class EvolvedLookerUp2_2_2(EvolvedLookerUp1_1_1):
185188
"""
186189
A 2_2_2 Lookerup trained with an evolutionary algorithm.
187190
188191
Names:
189192
- Evolved Lookerup 2 2 2: Original name by Marc Harper
190193
"""
191194
name = "EvolvedLookerUp2_2_2"
192-
193-
def __init__(self):
194-
pattern = 'CDCCDCCCDCDDDCCCDCDDDDDDDCDDDCDCDDDDCCDCCCCDDDDCCDDDDCCDCDDDDDDD'
195-
lookup_table = create_lookup_table_from_pattern(plays=2,
196-
op_plays=2,
197-
op_start_plays=2,
198-
pattern=pattern)
199-
super().__init__(lookup_table=lookup_table,
200-
initial_actions=(C, C))
195+
pattern = 'CDCCDCCCDCDDDCCCDCDDDDDDDCDDDCDCDDDDCCDCCCCDDDDCCDDDDCCDCDDDDDDD'
196+
parameters = (2, 2, 2)
197+
initial_actions = (C, C)
201198

202199

203-
class Winner12(LookerUp):
200+
class Winner12(EvolvedLookerUp1_1_1):
204201
"""
205202
A lookup table based strategy.
206203
207204
Names:
208205
- Winner12 [Mathieu2015]_
209206
"""
210207
name = "Winner12"
208+
pattern = 'CDCDDCDD'
209+
parameters = (1, 2, 0)
210+
initial_actions = (C, C)
211211

212-
def __init__(self):
213-
lookup_table_keys = create_lookup_table_keys(
214-
plays=1, op_plays=2, op_start_plays=0)
215-
216-
pattern = 'CDCDDCDD'
217-
# Zip together the keys and the action pattern to get the lookup table.
218-
lookup_table = dict(zip(lookup_table_keys, pattern))
219-
super().__init__(lookup_table=lookup_table,
220-
initial_actions=(C, C))
221212

222-
223-
class Winner21(LookerUp):
213+
class Winner21(EvolvedLookerUp1_1_1):
224214
"""
225215
A lookup table based strategy.
226216
227217
Names:
228218
- Winner21 [Mathieu2015]_
229219
"""
230220
name = "Winner21"
231-
232-
def __init__(self):
233-
lookup_table_keys = create_lookup_table_keys(
234-
plays=2, op_plays=1, op_start_plays=0)
235-
236-
pattern = 'CDCDCDDD'
237-
# Zip together the keys and the action pattern to get the lookup table.
238-
lookup_table = dict(zip(lookup_table_keys, pattern))
239-
super().__init__(lookup_table=lookup_table,
240-
initial_actions=(D, C))
221+
pattern = 'CDCDCDDD'
222+
parameters = (1, 2, 0)
223+
initial_actions = (D, C)

0 commit comments

Comments
 (0)