I'm trying to write a function in my tic-tac-toe program that checks to see if all three spaces in a line on the grid have been marked as either 'x's or 'o's. lst_1 is a list of all the possible combinations of lines:
def conc():
global lst
lst_1 = [[lst[0],lst[1],lst[2]],[lst[3],lst[4],lst[5]],[lst[6],lst[7],lst[8]],[lst[0],lst[3],lst[6]],[lst[1],lst[4],lst[7]], [lst[2],lst[5],lst[8]],[lst[0],lst[4],lst[8]],[lst[2],lst[4],lst[6]], [lst[0],lst[1],lst[2]],[lst[3],lst[4],lst[5]],[lst[0],lst[3],lst[6]], [lst[1],lst[4],lst[7]],[lst[2],lst[5],lst[8]],[lst[0],lst[4],lst[8]], [lst[2],lst[4],lst[6]]]
triplet = [s for s in lst_1]
if all('o' == item for item in triplet):
print('Player 2 wins!')
reply()
elif all('x' == item for item in triplet):
print('Player 1 wins!')
reply()
else:
pass
I thought this would stop the game when someone managed to get 3 in a row, but it keeps on going. Any ideas?