我想要做的事情是將'ad'(grid [0] [0])標記爲'A1',(grid [0] [1])爲'A2',( (grid [1] [0])爲'B1',(grid [1] [1])爲'B2',依此類推。我正在創建一個遊戲,玩家必須選擇座標以便在遊戲開始之前移除它的內容。在Python中標註多維數組座標
B W B W A1 A2 A3 A4 W B W B I want to access like this B1 B2 B3 B4 B W B W C1 C2 C3 C4
截至目前,我詢問用戶這一塊(「B」或「W」),他們想刪除(可以是任何自己的作品)。我希望他們能夠爲左上角'B'鍵入'A1'。
removeB = input("BLACK, remove one of your pieces by typing in it's coordinates")
我不知道如何去分配A1,A2,B1,B2 '變量' 到指定的座標。我希望能夠做一些事情,如:
if(removeB == A1): grid[row -1][col -1].append('-') # '-' = empty
如果有幫助,我重視我下面的代碼:
import random numrows = 3 numcols = 4 def initial(): grid = [] count = 0 y = 2 for x in range(numrows)s grid.append([]) for y in range(numcols): if ((x + y)%2): grid[x].append('W') else: grid[x].append('B') for x in grid: print(*x, sep=' ',end="\n") print("") color = input("Press 'Enter' to see which color you will be playing") print("") rand=random.randrange(1,3) if(rand == 1): print("Player1 you will be playing as BLACK") print("Player2 you will be playing as WHITE") else: print("Player1 you will be playing as WHITE") print("Player2 you will be playing as BLACK") print("") print(" The game board can be navigated as if it were: ") print("") example = '''\ A1 A2 A3 A4 B W B W B1 B2 B3 B4 = W B W B C1 C2 C3 C4 B W B W ''' print(example) print("and so on.....") print("") if(rand == 1): removeB = input("~BLACK Player, remove one of your pieces by typing in the coordinates: ") removeW = input("~WHITE Player, remove one of your pieces by typing in the coordinates: ") else: removeW = input("~WHITE Player, remove one of your pieces by typing in the coordinates: ") removeB = input("~BLACK Player, remove one of your pieces by typing in the coordinates: ")
預先感謝您的花費時間和精力回答我的問題。
P.S.我知道我的代碼很不方便。我只有3周進入蟒蛇大聲笑。我沒有完成代碼,只是掛在這部分....