循环执行功能并保存输出

时间:2018-12-28 14:18:28

标签: python

我正在使用最少冲突的N-Queens解算器,并希望循环该功能以获取所有可能的配置,然后保存它们并说出找到了多少个配置。主要功能如下所示。

编辑:抱歉,我使用的是我发现的here求解器。它会给我一个解决方案,但我需要所有可能的解决方案,并且不确定如何重复执行解决方案

eightQueen.initialize_board()生成一个随机的初始配置,而main函数为我提供了解决此配置所需的移动次数。

我想遍历所有可能的初始配置,并为每个初始配置打印移动数量。

def main():
    # Create a new instance of the minConflict class
    random.seed(datetime.now())

    number_of_rows = input("How many rows are on the board?")
    eightQueen = minConflict(number_of_rows)



    # Assigns the queens to their initial positions on the board then prints it
    eightQueen.initialize_board()
    eightQueen.print_board()

    #solves the given board and then prints it and the number of moves it had to take
    num_of_moves = eightQueen.solve_board()
    eightQueen.print_board()
    print ("It took", num_of_moves, "moves to solve this board")




if __name__ == "__main__":
    main()

0 个答案:

没有答案