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 masloo5000
from typing import List
def checkio(game_result: List[str]) -> str:
row1=game_result[0] #tworzenie osobnych zmiennych na kazdy wiersz (zeby mozna sie bylo dostac do poszczegolnego elementu)
row2=game_result[1]
row3=game_result[2]
if 'XXX' in row1: return 'X' #warunki na 3 X w jednym wierszu
if 'XXX' in row2: return 'X'
if 'XXX' in row3: return 'X'
if row1[0]==row2[1]==row3[2]=='X': return 'X' #warunki na przekÄ…tne z 3 X
if row1[2]==row2[1]==row3[0]=='X': return 'X'
for i in range (3):
if row1[i]==row2[i]==row3[i]=='X': return 'X' #warunki na 3 X lub O w jednej kolumnie
if row1[i]==row2[i]==row3[i]=='O': return 'O'
if 'OOO' in row1: return 'O' #3 raz O w jednym wierszu
if 'OOO' in row2: return 'O'
if 'OOO' in row3: return 'O'
if row1[0]==row2[1]==row3[2]=='O': return 'O' #OOO w przekatnej
if row1[2]==row2[1]==row3[0]=='O': return 'O'
return 'D' #jesli nic z tego to remis
if __name__ == '__main__':
print("Example:")
print(checkio(["X.O",
"XX.",
"XOO"]))
#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, 2018