示例#1
0
def __testIsWord():
    dictionary = WordFinder()
    dictionary.importFromList(['apple', 'notapple'])
    test = [
        Grid.Cell('a'),
        Grid.Cell('p'),
        Grid.Cell('p'),
        Grid.Cell('l'),
        Grid.Cell('e')
    ]
    print(dictionary.isWord(test))
    test = [
        Grid.Cell('a'),
        Grid.Cell('p'),
        Grid.Cell('p'),
        Grid.Cell('l'),
        Grid.Cell('o')
    ]
    print(dictionary.isWord(test))
示例#2
0
def __testPrePostShutOff():
    import Grid
    grid = Grid.Grid(2, 2)
    test_grid = [
        ['Tq', 'h',],# 'Tx'],
        ['Tcqvxz', 'j']# 'Tbcfgqvxz']
    ]
    for row in range(len(test_grid)):
        for col in range(len(test_grid[0])):
            if test_grid[row][col] != None:
                grid[row, col] = Grid.Cell(test_grid[row][col])

    print(str(grid))
    shutOffLeftRight(grid, 0, 1)
    shutOffLeftRight(grid, 1, 1)
    print(str(grid))
示例#3
0
    def getWords(self, line, minSize=2):
        minSize = min(self.__maxdepth, minSize)

        ret = []
        for start in range(
                len(line) - (minSize - 1)
        ):  # Start at all points except the last one (will not be adding one letter words)
            states = util.Queue()
            stateLine = line
            if start > 0:  # if not adding to beginning of line, add wall character to start of word
                if stateLine[start - 1].isChosen():
                    continue
                stateLine = copy.copy(
                    line)  # copy line so original not changed
                stateLine[start - 1] = Grid.CELL_WALL
            states.push(
                (stateLine, start, self.__dict)
            )  #insert starting state to queue. Values are line state, position in line, and dictionary level.

            while not states.isEmpty():
                currLine, pos, dictionaryLevel = states.pop()
                if pos >= len(line):
                    continue

                for validChar in line[pos]:
                    if validChar in dictionaryLevel:
                        newLine = copy.copy(currLine)
                        newLine[pos] = Grid.Cell(validChar)

                        if dictionaryLevel[validChar]['isComplete']:
                            #foundWord
                            if pos + 1 < len(
                                    newLine
                            ):  # if pos + 1 in line (no IndexError)
                                newLine[pos + 1] = Grid.CELL_WALL
                            if pos - start >= minSize:
                                ret.append(newLine)
                        states.push((newLine, pos + 1,
                                     dictionaryLevel[validChar]['letters']))
        return ret