Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Xs and Os Referee (Tic Tac Toe) solution in Clear category for Xs and Os Referee by faccanoni
from typing import List
def checkio(game_result: List[str]) -> str:
A=game_result
for i in range(3):
if A[i][0]==A[i][1]==A[i][2] and A[i][0]!='.':
return A[i][0]
for j in range(3):
if A[0][j]==A[1][j]==A[2][j] and A[0][j]!='.':
return A[0][j]
if (A[0][0]==A[1][1]==A[2][2] or A[0][2]==A[1][1]==A[2][0]) and A[1][1]!='.':
return A[1][1]
return "D"
if __name__ == '__main__':
print("Example:")
print(checkio([".O.","...","..."]))
#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!")
Jan. 26, 2021
Comments: