Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Xs and Os Referee solution in Clear category for Xs and Os Referee by tamsayhi
# migrated from python 2.7
def checkio(game_result):
cx = False
cy = False
if game_result[0] == 'XXX' or game_result[1] == 'XXX' or game_result[2] == 'XXX':
return 'X'
if game_result[0] == 'OOO' or game_result[1] == 'OOO' or game_result[2] == 'OOO':
return 'O'
nx = 0
ny = 0
for x in range(0,3):
for y in range(0,3):
if game_result[y][x] == 'X':
nx += 1
elif game_result[y][x] == 'O':
ny += 1
else:
continue
if nx == 3:
return 'X'
elif ny == 3:
return 'O'
else:
nx = 0
ny = 0
if game_result[0][0] == 'X':
if game_result[1][1] == 'X' and game_result[2][2] == 'X':
return 'X'
if game_result[0][0] == 'O':
if game_result[1][1] == 'O' and game_result[2][2] == 'O':
return 'O'
if game_result[0][2] == 'X':
if game_result[1][1] == 'X' and game_result[2][0] == 'X':
return 'X'
if game_result[0][2] == 'O':
if game_result[1][1] == 'O' and game_result[2][0] == 'O':
return 'O'
return 'D'
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
assert checkio([
"O.X",
"XX.",
"XOO"]) == "X", "Xs wins again"
Jan. 5, 2015
Comments: