-3

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.

Draken
  • 3,134
  • 13
  • 34
  • 54
user134456
  • 23
  • 6
  • 2
    Please see [How to ask](http://stackoverflow.com/help/how-to-ask) – Chanda Korat Mar 08 '17 at 11:43
  • 2
    What is the format of your data? How are you checking for columns and rows? I don't think you only expect a theoretical solution? – shad0w_wa1k3r Mar 08 '17 at 11:44
  • send some code and how is your data format (panda, list, list of list, numpy array ...) ? – Dadep Mar 08 '17 at 11:45
  • please show your code. – Vadim Mar 08 '17 at 11:47
  • 1
    if you map fields to numbers and they have logic, like 1,5,9 has step 4; 3,5,7 diagonal has step 2 ... think of it; there are many other ways of doing it and with little googling (means using google.com search engine) you could find examples because this is typical homework :) – Drako Mar 08 '17 at 11:47

1 Answers1

1

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)
Community
  • 1
  • 1
Vadim
  • 4,219
  • 1
  • 29
  • 44