As I just said, I'm writing a Tic-Tac-Toe game and an error ocurred that I'm still not able to fix. The Error itself involves the check of if the player has won. It doesn't show an explicit error message, but it just doesn't work how I wanted it to.
I first made a list of all the different winning possibillities. They look something like this:
gridwintest = [[True, True, True,
None, None, None,
None, None, None],
[None, None, None,
True, True, True,
None, None, None],
[None, None, None,
None, None, None,
True, True, True],
[True, None, None,
True, None, None,
True, None, None],
[None, True, None,
None, True, None,
None, True, None],
[None, None, True,
None, None, True,
None, None, True],
[True, None, None,
None, True, None,
None, None, True],
[None, None, True,
None, True, None,
True, None, None],
]
The function that handles them looks like this:
def check_grid(grid,check):
global gridwintest
gridvl = []
for item in grid:
if item == check:
gridvl.append(True)
else:
gridvl.append(None)
correct = True
for chkgrid in gridwintest:
for i in range(len(chkgrid)-1):
if not (chkgrid[i] == gridvl[i] or chkgrid[i] == None):
correct = False
return correct
The code that uses that function is:
if check_grid(gridvl, invcurrmode):
print("You won, "+currmode+"!")
quit()
elif check_grid(gridvl, currmode):
print("Try again, "+currmode+".")
quit()
But the return of the "check_grid" function is always false, even though if I logged the outputs of each line inside that function, it seems like it should actually be true.