Beispiel #1
0
    def tiles_from_string(cls, word):
        """
        Takes a string, with blanks in lowercase and pre-played tiles
        in parentheses, and returns a list of two lists of tiles: the
        first with all the tiles, and the other with just the played ones
        and None where tiles are on the board.
        Example: PORt(MANtEAU)X
        """
        without_parens = word.replace('()', '')  # remove parentheses
        
        all_tiles = []
        just_played_tiles = []
        
        for index, tile in enumerate(without_parens):
            if tile in '()':  #  skip over these
                continue
            first_part = word[:index]
            if first_part.count('(') > first_part.count(')'):  # on board
                if tile.islower():  # a blank
                    blank = Tile('?')
                    blank.set_face(tile.upper())
    
                    all_tiles.append(blank)
                    just_played_tiles.append(None)  # mark spot
                else:
                    all_tiles.append(Tile(tile))
                    just_played_tiles.append(None)  # mark spot
            else:  # belongs in both
                if tile.islower():  # a blank
                    blank = Tile('?')
                    blank.set_face(tile.upper())
    
                    just_played_tiles.append(blank)
                    all_tiles.append(blank)
                else:
                    just_played_tiles.append(Tile(tile))
                    all_tiles.append(Tile(tile))

        return [all_tiles, just_played_tiles]