Created
November 14, 2019 04:41
-
-
Save jamesshah/0f923249bc9fe2ae82f573ccb35b6796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Now we will check if player X or O has won,for every move after 5 moves. | |
if count >= 5: | |
if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ': # across the top | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ': # across the middle | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ': # across the bottom | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ': # down the left side | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ': # down the middle | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ': # down the right side | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ': # diagonal | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': # diagonal | |
printBoard(theBoard) | |
print("\nGame Over.\n") | |
print(" **** " +turn + " won. ****") | |
break | |
# If neither X nor O wins and the board is full, we'll declare the result as 'tie'. | |
if count == 9: | |
print("\nGame Over.\n") | |
print("It's a Tie!!") | |
# we have to change the player after every move. | |
if turn =='X': | |
turn = 'O' | |
else: | |
turn = 'X' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment