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 szneqz
def checkio(game_result):
fullstr = ""
x = 1
y = 0
count = 0
char = 'D'
for rows in game_result:
fullstr += rows
while(x <= 3 and y < 3):
if (fullstr[x + y * 3 - 1] == fullstr[x + 1 + y * 3 - 1] == fullstr[x + 2 + y * 3 - 1]) and fullstr[x + 2 + y * 3 - 1] != '.': #poziomo
print("poz")
return fullstr[x + y * 3 - 1]
x = 1
y += 1
x = 1
y = 1
while(x <= 3 and y < 3):
if (fullstr[x + 0 * y * 3 - 1] == fullstr[x + 1 * y * 3 - 1] == fullstr[x + 2 * y * 3 - 1]) and fullstr[x + 2 * y * 3 - 1] != '.': #pionowo
print("pio " + str(x) + " " + str(y))
return fullstr[x + y * 3 - 1]
y = 1
x += 1
x = 1
y = 1
if (fullstr[x + 0 + 0 * y * 3 - 1] == fullstr[x + 1 + 1 * y * 3 - 1] == fullstr[x + 2 + 2 * y * 3 - 1]) and fullstr[x + 0 + 0 * y * 3 - 1] != '.':
return fullstr[x + 0 + 0 * y * 3 - 1]
x = 1
y = 1
if (fullstr[x + 2 + 0 * y * 3 - 1] == fullstr[x + 1 + 1 * y * 3 - 1] == fullstr[x + 0 + 2 * y * 3 - 1]) and fullstr[x + 2 + 0 * y * 3 - 1] != '.':
return fullstr[x + 2 + 0 * y * 3 - 1]
return char
if __name__ == '__main__':
print(checkio([
"OOX",
"XXO",
"OXX"]))
#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. 22, 2018