I want to make a tic tac toe game.
I'm having trouble with the diagonal.
I've managed to find a way to check if a column or row is equal with a for loop.
I need a way to check if a diagonal is equal for every move made to see if someone won.
I want to make a tic tac toe game.
I'm having trouble with the diagonal.
I've managed to find a way to check if a column or row is equal with a for loop.
I need a way to check if a diagonal is equal for every move made to see if someone won.
Wellcome to StackOverFlow!
I recommend to use the numpy package.
x = np.arange(9).reshape((3,3))
x =
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
di = np.diag(x)
di
array([0, 4, 8])
now we need a check function for a list:
def checkEqual(lst):
return lst[1:] == lst[:-1]
after you can check the list if it is "equal":
checkEqual(di)