问题描述
我正在尝试制作一个机器人来读取 2048 游戏中的数据,并决定最佳动作。我已经为每个数字预设了灰度值。但不幸的是,空槽的灰度值和数字 512 是一样的。是否有任何简单的替代方法可以解决此问题?
The screenshot of the number 512
The screenshot of the empty slot
这是相关的代码:
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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)