コード例 #1
0
ファイル: __init__.py プロジェクト: IAlwaysBeCoding/TicTacToe
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 full_line_state(self,player):

        verify_player(player=player)
        players = generate_player_keys()
        players[PLAYER_MAP[player]] = self.length

        return self.create_line_state(**players)
コード例 #3
0
ファイル: compute.py プロジェクト: IAlwaysBeCoding/TicTacToe
def compute_hash(cell,player,mode=TTT_3_IN_A_ROW):

    verify_player(player=player)
    verify_cell(cell=cell,mode=mode)

    bits_to_push = (cell * 3) - 3

    return (1 << player + bits_to_push)
コード例 #4
0
ファイル: grid.py プロジェクト: IAlwaysBeCoding/TicTacToe
    def cells_taken(self,player=FREE_SPACE):

        verify_player(player=player)

        if player != FREE_SPACE:
            return [self[n] for n in self._state.get_taken_cells()
                    if self[n].player == player]

        else:
            return [self[n] for n in self._state.get_free_cells()]
コード例 #5
0
ファイル: cell.py プロジェクト: IAlwaysBeCoding/TicTacToe
def create_and_verify_cell(number,player,cell_class):

    verify_player(player=player)
    verify_cell(cell=number,mode=cell_class.MODE)

    ref_key = '{}-{}'.format(number,player)
    cell = cell_class._Refs.get(ref_key,None)

    if cell is None:
        cell = create_new_cell(cell_cls=cell_class,number=number,player=player)
        cell_class._Refs[ref_key] = cell
        cell_class._Hashes[cell.hash] = cell_class._Refs[ref_key]

    return cell
コード例 #6
0
ファイル: state.py プロジェクト: IAlwaysBeCoding/TicTacToe
 def player(self, player):
     verify_player(player=player)
     return self._permutations[0].count(player)