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 krzysztof.gonda
def checkio(game_result):
k=0
for row in game_result:
if(k==0): row0=row
if(k==1): row1=row
if(k==2): row2=row
k+=1
if(row0=="XXX" or row1=="XXX" or row2=="XXX"):
return "X"
if(row0[0]==row1[0]==row2[0]=='X' or row0[1]==row1[1]==row2[1]=='X' or row0[2]==row1[2]==row2[2]=='X' ):
return "X"
if((row0[0]==row1[1]==row2[2] or row0[2]==row1[1]==row2[0]) and row1[1]!='.'):
return row1[1]
if(row0=="OOO" or row1=="OOO" or row2=="OOO"):
return "O"
if(row0[0]==row1[0]==row1[0]=='O' or row0[1]==row1[1]==row2[1]=='O' or row0[2]==row1[2]==row2[2]=='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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Nov. 18, 2017