简体   繁体   English

Alpha Beta修剪之前的排序动作-井字游戏-python

[英]sorting move before alpha beta pruning - tic tac toe - python

I have the negascout or principal variation search algorithms working fine to solve tic tac toe. 我的negascout或主要变化搜索算法可以很好地解决井字游戏。 I have read somewhere that for these algorithms to be most efficient it is important to sort the moves such that the search starts with what is likely going to be the best move. 我在某处读到,为了使这些算法最有效,对动作进行排序很重要,这样搜索才能从可能最好的动作开始。

Assume the heuristic that in tic tac toe, the center square is better than a corner square, which is better than a side square. 假设在井字游戏中,试探中心广场优于角落广场,后者优于侧面广场。

I represent a square in tic tac toe by an integer between 1 and 9, as ordered on a numerical keypad. 我按数字键盘上的顺序,用1到9之间的整数表示井字游戏中的正方形。 In Python3, I am currently doing: 在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]

where candidate_move is the list of candidate moves, for example: 其中候选人_移动是候选移动的列表,例如:

candidate_move = [2, 5, 9]

The code returns: 代码返回:

[5, 9, 2]

It seems that ordering moves that way does not give any benefit in terms of computing time to solve tic tac toe. 看来以这种方式进行排序在解决井字游戏的计算时间方面没有任何好处。

Is there a more efficient way (in terms of computation speed) to code the function sort_candidate_move()? 是否有更有效的方式(就计算速度而言)对函数sort_candidate_move()进行编码?

Tic-tac-toe game is at most 9 steps, giving less than 9! 井字游戏最多9个步骤,少于9个步骤! different games. 不同的游戏。 For a problem of this scale all sensible algorithms will be superfast, so comparing their times will not show much difference. 对于这种规模的问题,所有明智的算法都将是超快的,因此比较它们的时间不会显示太大差异。 The algorithms' time-complexity estimates ("big O") are asymptotic, which means they are apparent only for problem of large to very-large size. 该算法的时间复杂度估计(“大O”)是渐近的,这意味着它们仅对大到非常大的问题才明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM