from __future__ import absolute_import

import axelrod.strategies

from .tournament_manager import *


class TournamentManagerFactory(object):

    @classmethod
    def create_tournament_manager(
            cls,
            output_directory,
            no_ecological,
            rebuild_cache,
            cache_file,
            exclusions,
            processes,
            turns,
            repetitions,
            noise):

        kwargs = {
            'processes': processes,
            'turns': turns,
            'repetitions': repetitions,
            'noise': noise
        }

        manager = axelrod.TournamentManager(
            output_directory=output_directory,
            with_ecological=not no_ecological,
            save_cache=rebuild_cache,
            cache_file=cache_file)

        cls._add_tournaments(manager, exclusions, kwargs)

        return manager

    @classmethod
    def _add_tournaments(cls, manager, exclusions, kwargs):
        for name, strategies in cls._tournaments_dict(exclusions).items():
            players = manager.one_player_per_strategy(strategies)
            manager.add_tournament(
                name=name, players=players, **kwargs)

    @staticmethod
    def _tournaments_dict(exclusions=[]):

        tournaments = {
            'basic_strategies': axelrod.basic_strategies,
            'strategies':
                axelrod.basic_strategies +
                axelrod.ordinary_strategies,
            'cheating_strategies': axelrod.cheating_strategies,
            'all_strategies':
                axelrod.basic_strategies +
                axelrod.ordinary_strategies +
                axelrod.cheating_strategies}

        return {
            key: value for
            key, value in tournaments.items() if key not in exclusions}

@@ -31,16 +31,52 @@
 e_import
+%0Afrom collections import OrderedDict
 %0A%0Aimport
@@ -1287,12 +1287,73 @@
 ons=
+None):%0A        if exclusions is None:%0A            exclusions = 
 %5B%5D
-):
 %0A%0A  
@@ -1368,25 +1368,37 @@
 urnaments = 
-%7B
+OrderedDict(%5B
 %0A           
@@ -1398,16 +1398,17 @@
         
+(
 'basic_s
@@ -1409,33 +1409,33 @@
 asic_strategies'
-:
+,
  axelrod.basic_s
@@ -1435,32 +1435,33 @@
 basic_strategies
+)
 ,%0A            's
@@ -1458,16 +1458,17 @@
         
+(
 'strateg
@@ -1463,33 +1463,33 @@
    ('strategies'
-:
+,
 %0A               
@@ -1551,32 +1551,33 @@
 inary_strategies
+)
 ,%0A            'c
@@ -1574,16 +1574,17 @@
         
+(
 'cheatin
@@ -1596,17 +1596,17 @@
 ategies'
-:
+,
  axelrod
@@ -1625,16 +1625,17 @@
 rategies
+)
 ,%0A      
@@ -1640,16 +1640,17 @@
         
+(
 'all_str
@@ -1657,17 +1657,17 @@
 ategies'
-:
+,
 %0A       
@@ -1791,17 +1791,28 @@
 rategies
-%7D
+)%0A        %5D)
 %0A%0A      
@@ -1820,17 +1820,29 @@
  return 
-%7B
+OrderedDict(%5B
 %0A       
@@ -1850,18 +1850,20 @@
     
+(
 key
-:
+,
  value
+)
  for
@@ -1933,10 +1933,20 @@
 clusions
-%7D
+%0A        %5D)
 %0A

Use ordered dict for tournaments.