5
5
from numpy import mean , nanmedian , std
6
6
7
7
from . import eigen
8
+ from .game import Game
8
9
import axelrod .interaction_utils as iu
9
10
10
11
try :
@@ -33,7 +34,7 @@ def wrapper(*args):
33
34
class ResultSet (object ):
34
35
"""A class to hold the results of a tournament."""
35
36
36
- def __init__ (self , players , interactions , progress_bar = True ):
37
+ def __init__ (self , players , interactions , progress_bar = True , game = None ):
37
38
"""
38
39
Parameters
39
40
----------
@@ -45,6 +46,10 @@ def __init__(self, players, interactions, progress_bar=True):
45
46
progress_bar : bool
46
47
Whether or not to create a progress bar which will be updated
47
48
"""
49
+ if game is None :
50
+ self .game = Game ()
51
+ else :
52
+ self .game = game
48
53
self .players = players
49
54
self .nplayers = len (players )
50
55
self .interactions = interactions
@@ -162,7 +167,8 @@ def build_scores(self):
162
167
for index_pair , repetitions in self .interactions .items ():
163
168
if index_pair [0 ] != index_pair [1 ]: # Ignoring self interactions
164
169
for repetition , interaction in enumerate (repetitions ):
165
- final_scores = iu .compute_final_score (interaction )
170
+ final_scores = iu .compute_final_score (interaction ,
171
+ self .game )
166
172
for player in range (2 ):
167
173
player_index = index_pair [player ]
168
174
player_score = final_scores [player ]
@@ -211,7 +217,8 @@ def build_wins(self):
211
217
player_index = index_pair [player ]
212
218
213
219
for rep , interaction in enumerate (repetitions ):
214
- winner_index = iu .compute_winner_index (interaction )
220
+ winner_index = iu .compute_winner_index (interaction ,
221
+ self .game )
215
222
if winner_index is not False and player == winner_index :
216
223
wins [player_index ][rep ] += 1
217
224
@@ -246,7 +253,9 @@ def build_normalised_scores(self):
246
253
for index_pair , repetitions in self .interactions .items ():
247
254
for repetition , interaction in enumerate (repetitions ):
248
255
if index_pair [0 ] != index_pair [1 ]: # Ignore self interactions
249
- scores_per_turn = iu .compute_final_score_per_turn (interaction )
256
+ scores_per_turn = iu .compute_final_score_per_turn (
257
+ interaction ,
258
+ self .game )
250
259
for player in range (2 ):
251
260
player_index = index_pair [player ]
252
261
score_per_turn = scores_per_turn [player ]
@@ -308,10 +317,14 @@ def build_payoffs(self):
308
317
309
318
if (player , opponent ) == index_pair :
310
319
for interaction in repetitions :
311
- utilities .append (iu .compute_final_score_per_turn (interaction )[0 ])
320
+ utilities .append (iu .compute_final_score_per_turn (
321
+ interaction ,
322
+ self .game )[0 ])
312
323
elif (opponent , player ) == index_pair :
313
324
for interaction in repetitions :
314
- utilities .append (iu .compute_final_score_per_turn (interaction )[1 ])
325
+ utilities .append (iu .compute_final_score_per_turn (
326
+ interaction ,
327
+ self .game )[1 ])
315
328
316
329
payoffs [player ][opponent ] = utilities
317
330
@@ -419,13 +432,15 @@ def build_score_diffs(self):
419
432
for opponent in plist :
420
433
if (player , opponent ) in self .interactions :
421
434
for repetition , interaction in enumerate (self .interactions [(player , opponent )]):
422
- scores = iu .compute_final_score_per_turn (interaction )
435
+ scores = iu .compute_final_score_per_turn (interaction ,
436
+ self .game )
423
437
diff = (scores [0 ] - scores [1 ])
424
438
score_diffs [player ][opponent ][repetition ] = diff
425
439
426
440
if (opponent , player ) in self .interactions :
427
441
for repetition , interaction in enumerate (self .interactions [(opponent , player )]):
428
- scores = iu .compute_final_score_per_turn (interaction )
442
+ scores = iu .compute_final_score_per_turn (interaction ,
443
+ self .game )
429
444
diff = (scores [1 ] - scores [0 ])
430
445
score_diffs [player ][opponent ][repetition ] = diff
431
446
@@ -458,11 +473,13 @@ def build_payoff_diffs_means(self):
458
473
for index_pair , repetitions in self .interactions .items ():
459
474
if (player , opponent ) == index_pair :
460
475
for interaction in repetitions :
461
- scores = iu .compute_final_score_per_turn (interaction )
476
+ scores = iu .compute_final_score_per_turn (interaction ,
477
+ self .game )
462
478
diffs .append (scores [0 ] - scores [1 ])
463
479
elif (opponent , player ) == index_pair :
464
480
for interaction in repetitions :
465
- scores = iu .compute_final_score_per_turn (interaction )
481
+ scores = iu .compute_final_score_per_turn (interaction ,
482
+ self .game )
466
483
diffs .append (scores [1 ] - scores [0 ])
467
484
if diffs :
468
485
payoff_diffs_means [player ][opponent ] = mean (diffs )
@@ -689,7 +706,7 @@ class ResultSetFromFile(ResultSet):
689
706
"""
690
707
691
708
def __init__ (self , filename , progress_bar = True ,
692
- num_interactions = False ):
709
+ num_interactions = False , game = None ):
693
710
"""
694
711
Parameters
695
712
----------
@@ -702,6 +719,10 @@ def __init__(self, filename, progress_bar=True,
702
719
displaying the progress bar, if it is not known and progress_bar
703
720
is set to True then an initial count will take place
704
721
"""
722
+ if game is None :
723
+ self .game = Game ()
724
+ else :
725
+ self .game = game
705
726
self .players , self .interactions = self ._read_csv (filename ,
706
727
progress_bar ,
707
728
num_interactions )
0 commit comments