Tic-tac-toe winner · 井字棋赢家
Tic-tac-toe winner
Decide a game of noughts and crosses from the board.
There are eight lines to check: three rows, three columns and two diagonals. board[r][c] is the square in row r and column c, so a column is board[0][c] + board[1][c] + board[2][c]. Collect all eight lines as three-letter strings, then look for "XXX" or "OOO".
井字棋赢家
根据棋盘判断井字棋的胜负。
一共要检查八条线:三行、三列和两条对角线。board[r][c] 是第 r 行、第 c 列的格子,所以一列是 board[0][c] + board[1][c] + board[2][c]。把八条线都收集成三个字母的字符串,再查找 "XXX" 或 "OOO"。
Write winner(board). board is a list of three strings, one per row, using X, O, and . for an empty square. Return "X" or · 或 "O" if that player has three in a row, column or diagonal, otherwise "". · 编写 winner(board)。board 是由三个字符串组成的列表,每个字符串是一行,用 X、O 表示棋子,. 表示空格。如果某位玩家在一行、一列或一条对角线上连成三个,返回 "X" 或 "O",否则返回 ""。
Click Run to see the output here. · 点击“运行”查看此处输出。