python中的扫雷舰设置值问题
我得用蟒蛇做扫雷艇。。我在手机游戏里的搜索有问题。随机地雷正在工作,但每个地雷的数量 我的代码 对于表中的i: 打印i 我的问题是:搜索和计数部分不起作用……你知道吗? 对于范围(10)内的x: 对于范围(10)内的y: 如果表[x][y]=“核武器”: 如果x==0: #这是左上角 如果y==0: 右(x,y-1) 底部(x+1,y) #这是右上角 如果y==10: 底部(x+1,y) 左(x,y-1) 其他: #其余的都吃完了 右(x,y-1) 底部(x+1,y) 左(x,y-1) elif x==10: #这是左下角 如果y==0: 向上(x-1,y) 右(x,y+1) #这是右下角 elif y==10: 左(x,y-1) 向上(x-1,y) 其他: #其余的在底部 右(x,y+1) 左(x,y-1) 向上(x-1,y) #其余的 其他: 右(x,y-1) 底部(x-1,y) 左(x,y-1)python中的扫雷舰设置值问题,python,python-2.7,Python,Python 2.7,我得用蟒蛇做扫雷艇。。我在手机游戏里的搜索有问题。随机地雷正在工作,但每个地雷的数量 我的代码 对于表中的i: 打印i 我的问题是:搜索和计数部分不起作用……你知道吗? 对于范围(10)内的x: 对于范围(10)内的y: 如果表[x][y]=“核武器”: 如果x==0: #这是左上角 如果y==0: 右(x,y-1) 底部(x+1,y) #这是右上角 如果y==10: 底部(x+1,y) 左(x,y-1) 其他: #其余的都吃完了 右(x,y-1) 底部(x+1,y) 左(x,y-1) elif
up(x-1,y)在运行整个程序之前,请您在IDE上分解代码,并每次尝试一些小部分,好吗?请准确描述什么不起作用。您是否收到错误消息?不正确的结果?您的脚本是否陷入循环中?理想情况下,提供一个表,以便我们可以轻松地重现问题。如果表[x][y]=“nuke”:Indexer:列表索引超出范围,这就是我的错误。ia将表设置为:#为炸弹插入随机导入随机#从用户插入数据(我的,数字)各表=[]数字=100矿矿=100矿矿=25+表=[]数字=100矿矿=100矿矿=25+表=[1010 10 10 10 10日日日日据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据据数字手机游戏=[“核弹”]*地雷+[“”]*(地雷数字)炸弹=[“核弹”]*地雷+[“”]*(地雷数字)随机。洗牌(炸弹)表=[炸弹[i:i+10]用于范围内的i(0,数字,10)]#################################
#i search every shell for "nuke". When it finds it the perimeter became " 1 "
def bottom(x,y):
if table[x][y]=="nuke":
table[x-1][y]=" 1 "
def right(x,y):
if table[x][y]=="nuke":
table[x][y-1]=" 1 "
def up(x,y):
if table[x][y]=="nuke":
table[x+1][y]=" 1 "
def left(x,y):
if table[x][y]=="nuke":
table[x][y+1]=" 1 "
#here I do the search
for x in range(10):
for y in range(10):
if table[x][y]!="nuke":
if x==0:
#here is the up left corner
if y==0:
right(x,y+1)
bottom(x+1,y)
#here is the up right corner
if y==10 :
bottom(x+1,y)
left(x,y-1)
else:
#the rest up
right(x,y+1)
bottom(x+1,y)
left(x,y-1)
elif x==10:
#here is the bottom left corner
if y==0:
up(x-1,y)
right(x,y+1)
#here is the bottom right corner
elif y==10:
left(x,y-1)
up(x-1,y)
else:
#the rest bottom
right(x,y+1)
left(x,y-1)
up(x-1,y)
#the rest
else:
right(x,y+1)
bottom(x+1,y)
left(x,y-1)
up(x-1,y)
#i change somethin to the end
#i search every shell for "nuke". When it finds it the perimeter became " 1 "
def bottom(x,y):
if table[x][y]=="nuke":
table[x-1][y]=" 1 "
def right(x,y):
if table[x][y]=="nuke":
table[x][y-1]=" 1 "
def up(x,y):
if table[x][y]=="nuke":
table[x+1][y]=" 1 "
def left(x,y):
if table[x][y]=="nuke":
table[x][y+1]=" 1 "
#here I do the search