Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Xs an Os Referee solution in Clear category for Xs and Os Referee by graffme
def checkio(game_result):
#warunki wygranej:
#skreślenie całego rzędu (przez X lub O)
#skreślenie całej kolumny (przez X lub O)
#sprawdź przekątne (przez X lub O)
#jeśli żaden z warunków nie rozstrzyga wygranej wydrukuj D***
#stwórz tablice - rzędy, columny i przekątne, znajdź w nich XXX lub OOO
rows = game_result[:]
columns = []
diagonals = []
for i in range(3):
column = ""
for j in range(3):
column = column + rows[j][i]
columns.append(column)
diagonals = [rows[0][0] + rows[1][1] + rows[2][2], rows[0][2] + rows[1][1] + rows[2][0]]
#szukaj zwycięzcy
if ("XXX" in rows) or ("XXX" in columns) or ("XXX" in diagonals):
return "X"
elif ("OOO" in rows) or ("OOO" in columns) or ("OOO" in diagonals):
return "O"
else:
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"
Jan. 12, 2017