井字游戏,有时也被称为“进攻和防守”,是一个两人玩家(X和O)轮流标志着3×3的网格的空间的连珠游戏。最先在任意一条直线(水平线,垂直线或对角线)上成功连接三个标记的一方获胜。
但我们不去玩这个游戏。你将是这个游戏的裁判。你被赋予游戏的结果,以及你必须判断游戏是平局还是有人胜出,以及谁将会成为最后的赢家。如果X玩家获胜,返回“X”。如果O玩家获胜,返回“O”。如果比赛是平局,返回“D”。
def checkio(game_result):
for row in game_result:if row[0] == row[1] == row[2] != ".":
return row[0]
for i in range(len(game_result)):
if game_result[0][i] == game_result[1][i] == game_result[2][i] != ".":
return game_result[0][i]
if game_result[0][0] == game_result[1][1] == game_result[2][2] != ".":
return game_result[0][0]
if game_result[0][2] == game_result[1][1] == game_result[2][0] != ".":
return game_result[0][2]
return "D"