我检查连接四赢的功能仅适用于第一行,但不适用于任何其他行。在我的代码的某处,x和y也混淆了,是我的循环吗?
def check_win(it):
#right diag - works
for x in range (0, 6):
for y in range (0, 5):
if board[x][y] == it and board[x-1][y+1] == it and board[x-2][y+2] == it and board[x-3][y+3] == it:
return True
#left diag- works
for x in range (0, 6):
for y in range (0, 5):
if board[x][y] == it and board[x-1][y-1] == it and board[x-2][y-2] == it and board[x-3][y-3] == it:
return True
#right- works
for y in range(0, 6):
if board[x][y] == it and board[x][y+1] == it and board[x][y+2] == it and board[x][y+3] == it:
return True
#down - works
for y in range(0, 6):
if board[x][y] == it and board[x-1][y] == it and board[x-2][y] == it and board[x-3][y] == it:
return True
return False
. . . . . . .
. . . . . . .
R . . . . . .
R . . . . . .
R . . . . . .
B B B B . . .
1 2 3 4 5 6 7
Game Over!
player 1 wins!
. . . . . . .
B . . . . . .
B . . . . . .
B . . . . . .
R R R R . . .
B R B R B . .
1 2 3 4 5 6 7