【问题标题】:sorting move before alpha beta pruning - tic tac toe - python在 alpha beta 修剪之前排序移动 - tic tac toe - python
【发布时间】:2018-11-16 15:14:45
【问题描述】:

我有 negascout 或主要变异搜索算法可以很好地解决井字游戏。我在某处读到,要使这些算法最有效,重要的是对移动进行排序,以便搜索从可能是最佳移动的开始。

假设在tic tac toe中,中心方块优于角方块,角方块优于边方块。

我用 1 到 9 之间的整数表示井字游戏中的正方形,按数字键盘上的顺序排列。在 Python3 中,我目前正在做:

def sort_candidate_move(candidate_move):
    # center > corner > side
    move_dict = {1: 'b', 2: 'c', 3: 'b', 4: 'c', 5: 'a', 6: 'c', 7: 'b', 8: 'c', 9: 'b'}
    to_sort = [(move_dict[move], move) for move in candidate_move]
    to_sort.sort()
    return [tup[1] for tup in to_sort]

其中 Candidate_move 是候选移动的列表,例如:

candidate_move = [2, 5, 9]

代码返回:

[5, 9, 2]

似乎以这种方式排序移动并没有在计算时间来解决井字游戏方面带来任何好处。

是否有更有效的方法(在计算速度方面)来编写函数 sort_candidate_move()?

【问题讨论】:

    标签: python sorting tic-tac-toe alpha-beta-pruning


    【解决方案1】:

    井字游戏最多9步,给不到9步!不同的游戏。对于这种规模的问题,所有合理的算法都将是超快的,因此比较它们的时间不会显示出太大的差异。算法的时间复杂度估计(“大 O”)是渐近的,这意味着它们仅对大到非常大的问题是明显的。

    【讨论】:

    • 问题是如何实现这样的功能——而不是这样的功能是否有意义......
    • 谢谢麦基。我问了井字游戏的问题。但我实际上正在研究更复杂的游戏,比如黑白棋。 reversi 中的搜索树足够大,优化我的函数 sort_candidate_move() 的代码显然很重要。
    • @quant 我并不是说这没有意义。我是说差异不会出现在任何测量中。我正在回答 OP 的担忧:“似乎以这种方式排序移动在计算时间来解决井字游戏方面没有任何好处。”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多