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 Vojtas
from typing import List
def victory (A , x ):
if A[0][0] == A[1][0] == A[2][0] ==x:
return x
elif A[0][1] == A[1][1] == A[2][1]==x:
return x
elif A[0][2] == A[1][2] == A[2][2] == x:#kolumny
return x
elif A[0][0] == A[0][1] == A[0][2] == x:
return x
elif A[1][0] == A[1][1] == A[1][2] == x:
return x
elif A[2][0] == A[2][1] == A[2][2] == x:#wiersze
return x
elif A[0][0] == A[1][1] == A[2][2] == x:#przekatne
return x
elif A[0][2] == A[1][1] == A[2][0] == x:
return x
else:
return 1
def checkio(game_result: List[str]) -> str:
A = [[0 for x in range(0, 3)] for y in range(0, 3)]
for i in range(0, 3):
for j in range(0, 3):
A[i][j] = game_result[i][j]
if victory(A, 'X') !=1:
return 'X'
elif victory(A, 'O')!=1:
return 'O'
else:
return 'D'
#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. 17, 2018