Skip to content

Commit 484faf5

Browse files
committed
MetaWinnerDeterministic and MetaWinnerStochastic
1 parent 89d7c44 commit 484faf5

File tree

4 files changed

+102
-42
lines changed

4 files changed

+102
-42
lines changed

axelrod/strategies/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from .meta import (
1010
MetaHunter, MetaHunterAggressive, MetaPlayer, MetaMajority,
1111
MetaMajorityMemoryOne, MetaMajorityFiniteMemory, MetaMajorityLongMemory,
12-
MetaMinority, MetaMixer, MetaWinner,
13-
MetaWinnerMemoryOne, MetaWinnerFiniteMemory, MetaWinnerLongMemory,
14-
MetaWinnerEnsemble, MWEDeterministic, MWEFast, MWEFiniteMemory,
15-
MWELongMemory, MWEMemoryOne, MWERandom, MWEStochastic
12+
MetaMinority, MetaMixer, MetaWinner, MetaWinnerDeterministic,
13+
MetaWinnerEnsemble, MetaWinnerMemoryOne, MetaWinnerFiniteMemory,
14+
MetaWinnerLongMemory, MetaWinnerStochastic, MWEDeterministic, MWEFast,
15+
MWEFiniteMemory, MWELongMemory, MWEMemoryOne, MWERandom, MWEStochastic
1616
)
1717

1818
all_strategies += [MetaHunter,
@@ -24,10 +24,12 @@
2424
MetaMinority,
2525
MetaMixer,
2626
MetaWinner,
27+
MetaWinnerDeterministic,
2728
MetaWinnerEnsemble,
2829
MetaWinnerMemoryOne,
2930
MetaWinnerFiniteMemory,
3031
MetaWinnerLongMemory,
32+
MetaWinnerStochastic,
3133
MWEDeterministic,
3234
MWEFast,
3335
MWEFiniteMemory,

axelrod/strategies/meta.py

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -283,27 +283,39 @@ def __init__(self):
283283
super(MetaMajorityMemoryOne, self).__init__(team=team)
284284

285285

286-
class MetaWinnerMemoryOne(MetaWinner):
287-
"""MetaWinner with the team of Memory One players"""
286+
class MetaMajorityFiniteMemory(MetaMajority):
287+
"""MetaMajority with the team of Finite Memory Players"""
288288

289-
name = "Meta Winner Memory One"
289+
name = "Meta Majority Finite Memory"
290290

291291
@init_args
292292
def __init__(self):
293-
team = [s for s in ordinary_strategies if s().classifier['memory_depth'] <= 1]
294-
super(MetaWinnerMemoryOne, self).__init__(team=team)
293+
team = [s for s in ordinary_strategies if s().classifier['memory_depth']
294+
< float('inf')]
295+
super(MetaMajorityFiniteMemory, self).__init__(team=team)
295296

296297

297-
class MetaMajorityFiniteMemory(MetaMajority):
298-
"""MetaMajority with the team of Finite Memory Players"""
298+
class MetaMajorityLongMemory(MetaMajority):
299+
"""MetaMajority with the team of Long (infinite) Memory Players"""
299300

300-
name = "Meta Majority Finite Memory"
301+
name = "Meta Majority Long Memory"
301302

302303
@init_args
303304
def __init__(self):
304305
team = [s for s in ordinary_strategies if s().classifier['memory_depth']
305-
< float('inf')]
306-
super(MetaMajorityFiniteMemory, self).__init__(team=team)
306+
== float('inf')]
307+
super(MetaMajorityLongMemory, self).__init__(team=team)
308+
309+
310+
class MetaWinnerMemoryOne(MetaWinner):
311+
"""MetaWinner with the team of Memory One players"""
312+
313+
name = "Meta Winner Memory One"
314+
315+
@init_args
316+
def __init__(self):
317+
team = [s for s in ordinary_strategies if s().classifier['memory_depth'] <= 1]
318+
super(MetaWinnerMemoryOne, self).__init__(team=team)
307319

308320

309321
class MetaWinnerFiniteMemory(MetaWinner):
@@ -318,28 +330,40 @@ def __init__(self):
318330
super(MetaWinnerFiniteMemory, self).__init__(team=team)
319331

320332

321-
class MetaMajorityLongMemory(MetaMajority):
322-
"""MetaMajority with the team of Long (infinite) Memory Players"""
333+
class MetaWinnerLongMemory(MetaWinner):
334+
"""MetaWinner with the team of Long (infinite) Memory Players"""
323335

324-
name = "Meta Majority Long Memory"
336+
name = "Meta Winner Long Memory"
325337

326338
@init_args
327339
def __init__(self):
328340
team = [s for s in ordinary_strategies if s().classifier['memory_depth']
329341
== float('inf')]
330-
super(MetaMajorityLongMemory, self).__init__(team=team)
342+
super(MetaWinnerLongMemory, self).__init__(team=team)
331343

332344

333-
class MetaWinnerLongMemory(MetaWinner):
334-
"""MetaWinner with the team of Long (infinite) Memory Players"""
345+
class MetaWinnerDeterministic(MetaWinner):
346+
"""Meta Winner Ensemble with the team of Deterministic Players."""
335347

336-
name = "Meta Winner Long Memory"
348+
name = "Meta Winner Deterministic"
337349

338350
@init_args
339351
def __init__(self):
340-
team = [s for s in ordinary_strategies if s().classifier['memory_depth']
341-
== float('inf')]
342-
super(MetaWinnerLongMemory, self).__init__(team=team)
352+
team = [s for s in ordinary_strategies if
353+
not s().classifier['stochastic']]
354+
super(MetaWinnerDeterministic, self).__init__(team=team)
355+
356+
357+
class MetaWinnerStochastic(MetaWinner):
358+
"""Meta Winner Ensemble with the team of Stochastic Players."""
359+
360+
name = "Meta Winner Stochastic"
361+
362+
@init_args
363+
def __init__(self):
364+
team = [s for s in ordinary_strategies if
365+
s().classifier['stochastic']]
366+
super(MetaWinnerStochastic, self).__init__(team=team)
343367

344368

345369
class MetaMixer(MetaPlayer):

axelrod/tests/unit/test_meta.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ def test_strategy(self):
270270
self.first_play_test(C)
271271

272272

273-
class TestMetaWinnerMemoryOne(TestMetaPlayer):
274-
name = "Meta Winner Memory One"
275-
player = axelrod.MetaWinnerMemoryOne
273+
class TestMetaMajorityFiniteMemory(TestMetaPlayer):
274+
name = "Meta Majority Finite Memory"
275+
player = axelrod.MetaMajorityFiniteMemory
276276
expected_classifier = {
277277
'memory_depth': float('inf'), # Long memory
278278
'stochastic': True,
279-
'makes_use_of': set(['game']),
280279
'long_run_time': True,
281280
'inspects_source': False,
281+
'makes_use_of': {'game'},
282282
'manipulates_source': False,
283283
'manipulates_state': False
284284
}
@@ -287,15 +287,32 @@ def test_strategy(self):
287287
self.first_play_test(C)
288288

289289

290-
class TestMetaMajorityFiniteMemory(TestMetaPlayer):
291-
name = "Meta Majority Finite Memory"
292-
player = axelrod.MetaMajorityFiniteMemory
290+
class TestMetaMajorityLongMemory(TestMetaPlayer):
291+
name = "Meta Majority Long Memory"
292+
player = axelrod.MetaMajorityLongMemory
293293
expected_classifier = {
294294
'memory_depth': float('inf'), # Long memory
295295
'stochastic': True,
296296
'long_run_time': True,
297297
'inspects_source': False,
298-
'makes_use_of': {'game'},
298+
'makes_use_of': {'game', 'length'},
299+
'manipulates_source': False,
300+
'manipulates_state': False
301+
}
302+
303+
def test_strategy(self):
304+
self.first_play_test(C)
305+
306+
307+
class TestMetaWinnerMemoryOne(TestMetaPlayer):
308+
name = "Meta Winner Memory One"
309+
player = axelrod.MetaWinnerMemoryOne
310+
expected_classifier = {
311+
'memory_depth': float('inf'), # Long memory
312+
'stochastic': True,
313+
'makes_use_of': set(['game']),
314+
'long_run_time': True,
315+
'inspects_source': False,
299316
'manipulates_source': False,
300317
'manipulates_state': False
301318
}
@@ -321,9 +338,9 @@ def test_strategy(self):
321338
self.first_play_test(C)
322339

323340

324-
class TestMetaMajorityLongMemory(TestMetaPlayer):
325-
name = "Meta Majority Long Memory"
326-
player = axelrod.MetaMajorityLongMemory
341+
class TestMetaWinnerLongMemory(TestMetaPlayer):
342+
name = "Meta Winner Long Memory"
343+
player = axelrod.MetaWinnerLongMemory
327344
expected_classifier = {
328345
'memory_depth': float('inf'), # Long memory
329346
'stochastic': True,
@@ -338,9 +355,26 @@ def test_strategy(self):
338355
self.first_play_test(C)
339356

340357

341-
class TestMetaWinnerLongMemory(TestMetaPlayer):
342-
name = "Meta Winner Long Memory"
343-
player = axelrod.MetaWinnerLongMemory
358+
class TestMetaWinnerDeterministic(TestMetaPlayer):
359+
name = "Meta Winner Deterministic"
360+
player = axelrod.MetaWinnerDeterministic
361+
expected_classifier = {
362+
'memory_depth': float('inf'), # Long memory
363+
'stochastic': False,
364+
'long_run_time': True,
365+
'inspects_source': False,
366+
'makes_use_of': {'game', 'length'},
367+
'manipulates_source': False,
368+
'manipulates_state': False
369+
}
370+
371+
def test_strategy(self):
372+
self.first_play_test(C)
373+
374+
375+
class TestMetaWinnerStochastic(TestMetaPlayer):
376+
name = "Meta Winner Stochastic"
377+
player = axelrod.MetaWinnerStochastic
344378
expected_classifier = {
345379
'memory_depth': float('inf'), # Long memory
346380
'stochastic': True,

docs/tutorials/advanced/classification_of_strategies.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ strategies::
4747
... }
4848
>>> strategies = axl.filtered_strategies(filterset)
4949
>>> len(strategies)
50-
56
50+
57
5151

5252

5353
Or, to find out how many strategies only use 1 turn worth of memory to
@@ -81,7 +81,7 @@ length of each match of the tournament::
8181
... }
8282
>>> strategies = axl.filtered_strategies(filterset)
8383
>>> len(strategies)
84-
17
84+
19
8585

8686
Note that in the filterset dictionary, the value for the 'makes_use_of' key
8787
must be a list. Here is how we might identify the number of strategies that use
@@ -92,7 +92,7 @@ both the length of the tournament and the game being played::
9292
... }
9393
>>> strategies = axl.filtered_strategies(filterset)
9494
>>> len(strategies)
95-
11
95+
13
9696

9797
Some strategies have been classified as having a particularly long run time::
9898

@@ -101,7 +101,7 @@ Some strategies have been classified as having a particularly long run time::
101101
... }
102102
>>> strategies = axl.filtered_strategies(filterset)
103103
>>> len(strategies)
104-
18
104+
20
105105

106106
Strategies that :code:`manipulate_source`, :code:`manipulate_state`
107107
and/or :code:`inspect_source` return :code:`False` for the :code:`obey_axelrod`

0 commit comments

Comments
 (0)