有没有一种方法可以避免单词搜索游戏中单词的重叠?

时间:2019-12-11 15:17:30

标签: python-3.x search word

在此功能中,程序将用户输入的四个单词放入列表中,并将其随机放入10x10矩阵中。问题有时是由于random.randiant,来自水平/垂直/对角线的单词彼此重叠。

有办法避免这种情况发生吗?

    def add(word, puzzle):
    temp = random.randint(0, 2)
    if temp == 0:
        row = random.randint(0, 14)
        column = random.randint(0, 12-len(word))
        for i in range(0, len(word)):
            puzzle[row][column+i] = word[i]
    elif temp == 1:
        column = random.randint(0, 14)
        row = random.randint(0, 14-len(word))
        for i in range(0, len(word)):
            puzzle[row+i][column] = word[i]
    else:
        row = random.randint(0, 14-len(word))
        for i in range(0, len(word)):
            puzzle[row+i][row+i+1] = word[i]

0 个答案:

没有答案