0

我正在尝试制作一个机器人来读取游戏 2048 中的数据,并决定最佳动作。我已经为每个数字预设了灰度值。但不幸的是,空槽的灰度值和数字 512 是相同的。有没有简单的方法可以解决这个问题?

512号截图

空槽截图

这是相关代码:

class Values:
    empty = 195
    two = 230
    four = 225
    eight = 190
    sixteen = 172
    threeTwo = 154
    sixFour = 136
    oneTwoEight = 204
    twoFiveSix = 200
    fiveOneTwo = 195
    oneZeroTwoFour = 193
    twoZeroFourEight = 189

valueArray = [empty, two, four, eight,
              sixteen, threeTwo, sixFour,
              oneTwoEight, twoFiveSix, fiveOneTwo,
              oneZeroTwoFour, twoZeroFourEight]

screenImage = ImageGrab.grab()
grayScreenImage = ImageOps.grayscale(screenImage)
for index, cord in enumerate(Coordinates.coordinateArray):
    pixel = grayScreenImage.getpixel(cord)
    try:
        position = Values.valueArray.index(pixel)
        
    except:
        position = 0

    if position == 0:
        currentGrid[index] = 0
    else:
        currentGrid[index] = 2 ** position
4

0 回答 0