Nie wiem dlaczego warunek w podanym kodzie jest prawdziwy co skutkuje wykonaniem instrukcji break.
Przecież X lub O nie równa się 0.
import random as r
game = [[0,0,0],
[0,0,0],
[0,0,0]]
def table():
print(game[0])
print(game[1])
print(game[2])
def computer(result,p_c = "X",n = 0,num = 0):
if n:
num = int(input("Podaj pozycje z zakresu 1-9"))
if num-n <= 2:
if game[0][num-n] == 0:
game[0][num-n] = p_c
result = False
elif num-n <= 5:
if num-n == 3:
if game[1][0] == 0:
game[1][0] = p_c
result = False
elif num-n == 4:
if game[1][1] == 0:
game[1][1] = p_c
result = False
else:
if game[1][2] == 0:
game[1][2] = p_c
result = False
elif num-n <= 8:
if num-n == 6:
if game[2][6] == 0:
game[2][6] = p_c
result = False
elif num-n == 7:
if game[2][7] == 0:
game[2][7] = p_c
result = False
else:
if game[2][8] == 0:
game[2][8] = p_c
result = False
print("Witaj w grze O i X")
while True:
if (game[0][0] and game[0][1] and game[0][2] == "X" or "O") or (game[1][0] and game[1][1] and game[1][2] == "X" or "O") or (game[2][0] and game[2][1] and game[2][2] == "X" or "O") or (game[0][0] and game[1][0] and game[2][0] == "X" or "O") or(game[0][1] and game[1][1] and game[2][1] == "X" or "O") or (game[0][2] and game[1][2] and game[2][2] == "X" or "O") or (game[0][0] and game[1][1] and game[2][2] == "X" or "O") or (game[0][2] and game[1][1] and game[2][0] == "X" or "O"):
break
a = True
b =True
c = True
table()
while a == True:
computer(a,"O",1)
table()
while b == True:
computer(b,r.randint(range(9),1))
table()
while c == True:
computer(c,"O",1)
table()
print("Koniec Gry")
table()