19
19
from .action import Action
20
20
from .player import Player
21
21
22
- CachePlayerKey = Tuple [Player , Player , int ]
23
- CacheKey = Tuple [str , str , int ]
22
+ CachePlayerKey = Tuple [Player , Player ]
23
+ CacheKey = Tuple [str , str ]
24
24
25
25
26
26
def _key_transform (key : CachePlayerKey ) -> CacheKey :
@@ -29,15 +29,15 @@ def _key_transform(key: CachePlayerKey) -> CacheKey:
29
29
Parameters
30
30
----------
31
31
key: tuple
32
- A 3-tuple: (player instance, player instance, match length )
32
+ A 3-tuple: (player instance, player instance)
33
33
"""
34
- return key [0 ].name , key [1 ].name , key [ 2 ]
34
+ return key [0 ].name , key [1 ].name
35
35
36
36
37
37
def _is_valid_key (key : CachePlayerKey ) -> bool :
38
38
"""Validate a deterministic cache player key.
39
39
40
- The key should always be a 3 -tuple, with a pair of axelrod.Player
40
+ The key should always be a 2 -tuple, with a pair of axelrod.Player
41
41
instances and one integer. Both players should be deterministic.
42
42
43
43
Parameters
@@ -48,13 +48,12 @@ def _is_valid_key(key: CachePlayerKey) -> bool:
48
48
-------
49
49
Boolean indicating if the key is valid
50
50
"""
51
- if not isinstance (key , tuple ) or len (key ) != 3 :
51
+ if not isinstance (key , tuple ) or len (key ) != 2 :
52
52
return False
53
53
54
54
if not (
55
55
isinstance (key [0 ], Player )
56
56
and isinstance (key [1 ], Player )
57
- and isinstance (key [2 ], int )
58
57
):
59
58
return False
60
59
@@ -83,10 +82,11 @@ def _is_valid_value(value: List) -> bool:
83
82
class DeterministicCache (UserDict ):
84
83
"""A class to cache the results of deterministic matches.
85
84
86
- For fixed length matches with no noise between pairs of deterministic
87
- players, the results will always be the same. We can hold those results
88
- in this class so as to avoid repeatedly generating them in tournaments
89
- of multiple repetitions.
85
+ For matches with no noise between pairs of deterministic players, the
86
+ results will always be the same. We can hold the results for the longest
87
+ run in this class, so as to avoid repeatedly generating them in tournaments
88
+ of multiple repetitions. If a shorter or equal-length match is run, we can
89
+ use the stored results.
90
90
91
91
By also storing those cached results in a file, we can re-use the cache
92
92
between multiple tournaments if necessary.
@@ -134,8 +134,7 @@ def __setitem__(self, key: CachePlayerKey, value):
134
134
135
135
if not _is_valid_key (key ):
136
136
raise ValueError (
137
- "Key must be a tuple of 2 deterministic axelrod Player classes "
138
- "and an integer"
137
+ "Key must be a tuple of 2 deterministic axelrod Player classes"
139
138
)
140
139
141
140
if not _is_valid_value (value ):
0 commit comments