我需要python的五子棋代码
时间: 2023-03-12 22:42:05 浏览: 48
很高兴为您提供帮助。这是一段简单的Python五子棋代码:board = [[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 2, 0, 0, 0],
[0, 0, 0, 2, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]]def check_five_in_a_row(board, x, y, player):
directions = [[1, 0], [-1, 0], [0, 1], [0, -1],
[1, 1], [-1, -1], [1, -1], [-1, 1]] for d in directions:
count = 0
for i in range(1, 5):
x_val, y_val = x + i*d[0], y + i*d[1]
if not 0 <= x_val < 8 or not 0 <= y_val < 8 or board[x_val][y_val] != player:
break
count += 1
if count == 4:
return True
return False
阅读全文