python - Logical flow in tic-tac-toe issue -


i'm trying make tic-tac-toe game. not sure convention is, used 1 x , 4 o, since sum of 3 on column, row, or diagonal mean win x, , sum of 12 mean win o, , combination cannot reached in non-winning scenario. similarly, if rows, columns, , diagonals equal 1,1,4 or 1,4,4 (i.e. 6 or 9) game draw.

the rest of game works fine, except win conditions:

#if row, column, or diagonal sums 3, win, if 12, win  #a number 1 = x, number 4 = o if (    row1 == 3     or  row2 == 3     or  row3 == 3     or  col1 == 3     or  col2 == 3     or  col3 == 3     or  dia1 == 3     or  dia2 == 3     ):     endcondition = true     whowon = "you won!"  if (    row1 == 12     or  row2 == 12     or  row3 == 12     or  col1 == 12     or  col2 == 12     or  col3 == 12     or  dia1 == 12     or  dia2 == 12     ):     endcondition = true     whowon = "you lost! computer wins."  #if last spot, draw #a losing row either 1,1,4 or 1,4,4 equal 6 , 9 respectively if (row1 , row2 , row3 , col1 , col2 , col3 , dia1 , dia2) == (6 or 9):     endcondition = true     whowon = "no one. draw." 

any help? know it's simple mistake somewhere.

if (row1 , row2 , row3 , col1 , col2 , col3 , dia1 , dia2) == (6 or 9): 

this not proper syntax checking multiple values against multiple other values. (6 or 9) evaluate 9. (row1 , row2 , ... , dia2) evaluate either 0 if of values 0; or value of dia2 if none of values 0. conditional incorrectly evaluate false if board full , dia2 other 9.

instead, try:

if all(x == 6 or x == 9 x in (row1, row2, row3, col1, col2, col3, dia1, dia2)): 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -