python

时间:2019-01-14 18:20:19

标签: python python-2.7

我必须在python中制作扫雷器。.我在手机游戏内搜索时遇到问题..随机地雷在起作用,但每枚地雷的数量

我的代码

    #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:         打印我

我的问题是:搜索和计数这一部分不起作用。您对此有任何了解吗?

1 个答案:

答案 0 :(得分:0)

#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

对于x范围(10):     对于范围(10)中的y:         如果table [x] [y]!=“ nuke”:                 如果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)                     向上(x-1,y)