我想檢查井字遊戲中所有可能的贏家條件,我如何以功能性方式重寫?檢查tic-tac-toe的優勝者 - NumPy/Python
board = numpy.array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
player = 1
if any([(board[0, :] == player).all(),
(board[:, 0] == player).all(),
(board[1, :] == player).all(),
(board[:, 1] == player).all(),
(board[2, :] == player).all(),
(board[:, 2] == player).all()]):
print('Win')
不要忘記檢查對角線勝。 –
記得@TomKarzes! – Skhaz