Пример #1
0
def generate_combinations(players_to_combine,length):


    if not isinstance(players_to_combine,(list,tuple)):
        raise TicTacToeException(
                'players_to_combine  needs to be a list with 1 or 2 '\
                'items : {} as player_0 , {} as player_1 and ' \
                '{} as player_2 .No other items besides '\
                'those .'.format(FREE_SPACE,PLAYER_1,PLAYER_2))

    for p in players_to_combine:
        verify_player(player=p)


    combinations = []

    for pattern in combinations_with_replacement(players_to_combine,length):
        pattern_combinations = player_combinations(
                                             player_0 = pattern.count(FREE_SPACE),
                                             player_1 = pattern.count(PLAYER_1) ,
                                             player_2 = pattern.count(PLAYER_2)
                                             )

        for combination in pattern_combinations:
            p = [combination.count(FREE_SPACE),
                 combination.count(PLAYER_1) ,
                 combination.count(PLAYER_2)]

            if p not in combinations:
                combinations.append(p)

    return combinations
Пример #2
0
    def create_line_state(self,player_0,player_1,player_2):

        state_name   = self.create_line_state_name(player_0,player_1,player_2)
        combinations = player_combinations(player_0,player_1,player_2)

        return LineState(name=state_name,permutations=combinations,length=self.length)