Dec-22-2019, 06:16 AM
Hi, I'm new to coding and trying to make a tic tac toe game. I'm almost finished but i cannot figure out how to create a win check mechanic... So far i have created a list of lists containing possible win values and also created 2 lists one for each player that save the value of there move after each move. My question is, how would one compare the items in a player list to see if any 3 combinations of moves is equal to any of the items in the wins list? Any help would be so much appreciated I've been stuck for days on this, I've posted a the code below Thanks In Advance
Also in the code below, keep in mind, the player list starts empty and only gets added to after the player move. So after first move i get an error saying "not enough arguments expected 3 received 1"
If i remove the j and k variables and just use a for i loop all i get is "no winner"
and, for the for i,j,k loop, i even tried starting the player lists with 2 none arguments to start but it still just prints no winner.
Again, thanks for any help.
Also in the code below, keep in mind, the player list starts empty and only gets added to after the player move. So after first move i get an error saying "not enough arguments expected 3 received 1"
If i remove the j and k variables and just use a for i loop all i get is "no winner"
and, for the for i,j,k loop, i even tried starting the player lists with 2 none arguments to start but it still just prints no winner.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wins_list = [[ 0 , 1 , 2 ],[ 3 , 4 , 5 ],[ 6 , 7 , 8 ],[ 0 , 3 , 6 ],[ 1 , 4 , 7 ],[ 2 , 5 , 8 ],[ 0 , 4 , 8 ],[ 2 , 4 , 6 ]] #new_list = str(wins_list) ##thought maybe a string would help but doesnt seem to work but also player1_peices = [ 1 , 4 , 6 , 2 ] ##example list for testing player2_peices = [ 3 , 8 , 0 ] ##example list for testing ##here after first move i get an error saying not enough arguments expected 3 recieved 1## ##if i remove the j and k variables and just use a for i loop all i get is no winner ## for i,j,k in wins_list: if i in player1_pieces and j in player1_pieces and k in player1_pieces: print ( "x wins" ) elif i in player2_pieces and j in player2_pieces and k in player2_pieces: print ( "o wins" ) else : print ( "no winner" ) |