Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Xs and Os Referee by hjozwowiak
def checkio(game_result):
import re
firstRow = ""
secondRow = ""
thirdRow = ""
result = None
for i in range(0,3):
firstRow += game_result[i][0]
for i in range(0,3):
secondRow += game_result[i][1]
for i in range(0,3):
thirdRow += game_result[i][2]
rotated_game_result = [firstRow,secondRow,thirdRow]
rotated = zip(game_result)
for hLine in game_result:
if("O" not in hLine and "." not in hLine):
return "X"
elif("X" not in hLine and "." not in hLine):
return "O"
elif("X" not in hLine and "O" not in hLine):
result = "D"
for vLine in rotated_game_result:
if("O" not in vLine and "." not in vLine):
return "X"
elif("X" not in vLine and "." not in vLine):
return "O"
elif("X" not in vLine and "O" not in vLine):
result = "D"
if(game_result[0][0] == "X" and game_result[1][1] == "X" and game_result[2][2] == "X" or game_result[0][2] == "X" and game_result[1][1] == "X" and game_result[2][0] == "X"):
return "X"
elif(game_result[0][0] == "O" and game_result[1][1] == "O" and game_result[2][2] == "O" or game_result[0][2] == "O" and game_result[1][1] == "O" and game_result[2][0] == "O"):
return "O"
else:
result = "D"
if (result == "D"):
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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Nov. 18, 2017