Created
September 28, 2015 06:24
-
-
Save vaibhavmule/511716fb159aa853bcf9 to your computer and use it in GitHub Desktop.
Tic Tac Toe game checker.
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
first_input = list(raw_input()) | |
second_input = list(raw_input()) | |
third_input = list(raw_input()) | |
def tictactoe(first_row, second_row, third_row): | |
if check_horizontal(first_row, second_row, third_row) == True: | |
res = True | |
elif check_verticle(first_row, second_row, third_row) == True: | |
res = True | |
elif check_diagonal(first_row, second_row, third_row) == True: | |
res = True | |
else: | |
res = False | |
return res | |
def check_horizontal(one, two, three): | |
if one == ['x', 'x', 'x'] or one == ['o', 'o', 'o']: | |
res = True | |
elif two == ['x', 'x', 'x'] or two == ['o', 'o', 'o']: | |
res = True | |
elif three == ['x', 'x', 'x'] or three == ['o', 'o', 'o']: | |
res = True | |
else: | |
res = False | |
return res | |
def check_verticle(verticle_one, verticle_two, verticle_three): | |
first_verticle = list( | |
verticle_one[0] + verticle_two[0] + verticle_three[0]) | |
second_verticle = list( | |
verticle_one[1] + verticle_two[1] + verticle_three[1]) | |
third_verticle = list( | |
verticle_one[2] + verticle_two[2] + verticle_three[2]) | |
if first_verticle == ['x', 'x', 'x'] or first_verticle == ['o', 'o', 'o']: | |
res = True | |
elif second_verticle == ['x', 'x', 'x'] or second_verticle == ['o', 'o', 'o']: | |
res = True | |
elif third_verticle == ['x', 'x', 'x'] or third_verticle == ['o', 'o', 'o']: | |
res = True | |
else: | |
res = False | |
return res | |
def check_diagonal(one, two, three): | |
left_diagonal = list(one[0] + two[1] + three[2]) | |
right_diagonal = list(one[2] + two[1] + three[0]) | |
if left_diagonal == ['x', 'x', 'x'] or left_diagonal == ['o', 'o', 'o']: | |
res = True | |
elif right_diagonal == ['x', 'x', 'x'] or right_diagonal == ['o', 'o', 'o']: | |
res = True | |
else: | |
res = False | |
return res | |
print tictactoe(first_input, second_input, third_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment