繁体   English   中英

2048个启发式,意外结果

[英]2048 heuristic, unexpected results

我正在使用2048的AI。到目前为止,它非常简单,我基本上是在尝试制作减少蛇形的“蛇”,因此完美的游戏应如下所示: 完美的游戏 ,尽管这和它一样好: 在此处输入图片说明

我的启发式方法是使用一个简单的2d数组,该数组将每个单元格的大小随着摇动形状的减小而相乘,例如:

---------------------
| 16 | 15 | 14 | 13 |
| 9  | 10 | 11 | 12 |
| 8  | 7  | 6  | 5  |
| 1  | 2  | 3  | 4  |
---------------------

这相对有效,大约有一半的时间达到2048,但有时它做出的决策确实很奇怪,例如:

建议正确,正确建议

建议正确,正确建议

建议向下,正确左

建议向下,正确为左/右

是否可以调整权重或添加某种惩罚来惩罚这种行为? 其他所有内容都可以正常工作,甚至从数学上讲,其中的一些都没有任何意义。 F.ex. #3显然比左边更好,向下最大被乘数在拐角处,将256合并到拐角处应该产生最佳结果?

编辑:

def getBestMove(node, depth):
    bestValue, bestAction = -1, None
    for direction in xrange(4):
        temp, score, moved = Board.move(node, direction)
        if not moved: continue
        val = minimax(temp, depth - 1, False)
        if val > bestValue:
            bestValue = val
            bestAction = direction
    return bestValue, bestAction


def minimax(node, depth, maximizingPlayer):
    if depth == 0:
        return heuristic(node)
    elif Board.isLost(node):
        return 0

    if maximizingPlayer:
        bestValue = -1
        for direction in xrange(4):
            temp, score, moved = Board.move(node, direction)
            if not moved: continue
            val = minimax(temp, depth - 1, False)
            if val > bestValue: bestValue = val
        return bestValue
    else:
        bestValue = 1<<20
        for cell in Board.getFreeCells(node):
            for cellValue in [2, 4]:
                temp = deepcopy(node)
                temp[cell[0]][cell[1]] = cellValue

                val = minimax(temp, depth - 1, True)
                if val < bestValue: bestValue = val
        return bestValue

是我使用的minimax的基本实现。 所描述的启发式函数是2D数组的简单乘法。 一个是电路板本身,另一个是遮罩,总共有4个遮罩,这就是从四个不同的角开始以递减的数字表示的“蛇”:

def heuristic(board):
    return max([mulArr(board, grid) for grid in grids])


def mulArr(arr1, arr2):
    return sum([arr1[i][j]*arr2[i][j] for i in xrange(len(arr1)) for j in xrange(len(arr1))])

为了您的挑衅,您可以尝试:

| 32768 16384 8192 4096 |
|  256   512  1024 2048 |
|  128    64   32   16  |
|   1     2     4    8  |

并找到最小值?

暂无
暂无

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

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