【发布时间】: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