how to use numpy to shorten my code where i check if you win or not
i need to find a way to use numpy to fit into my code because its very long and hard. i check diag, horizontle and row but i need to find a way to shorten it with numpy
def checkHorizontle(board):
global winner
if board[0] == board[1] == board[2] and board[1] != "-":
winner = board[0]
return True
elif board[3] == board[4] == board[5] and board[3] != "-":
winner = board[3]
return True
elif board[6] == board[7] == board[8] and board[6] != "-":
winner = board[6]
return True
def checkRow(board):
global winner
if board[0] == board[3] == board[6] and board[0] != "-":
winner = board[0]
return True
elif board[1] == board[4] == board[7] and board[1] != "-":
winner = board[1]
return True
elif board[2] == board[5] == board[8] and board[2] != "-":
winner = board[2]
return True
def checkDiag(Board):
global winner
if board[0] == board[4] == board[8] and board[0] != "-":
winner = board[0]
return True
elif board[2] == board[4] == board[6] and board[2] != "-":
winner = board[2]
return True
when i tried to find a sulution my mind just decided to quit. i know you could youe the magic square to find it and the numpy multiply fuction but i dont know how to
There is no need for numpy, you can use a simple loop: