Tic-tac-toe winner · Pemenang tic-tac-toe
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".
Pemenang tic-tac-toe
Tentukan pemenang permainan noughts and crosses dari papan permainan.
Ada delapan garis yang perlu dicek: tiga baris, tiga kolom, dan dua diagonal. board[r][c] adalah kotak di baris r dan kolom c, jadi sebuah kolom adalah board[0][c] + board[1][c] + board[2][c]. Kumpulkan semua delapan garis sebagai string tiga huruf, lalu cari "XXX" atau "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 "". · Tulis winner(board). board adalah daftar tiga string, satu per baris, menggunakan X, O, dan . untuk kotak kosong. Kembalikan "X" atau "O" jika pemain tersebut memiliki tiga berturut-turut dalam baris, kolom, atau diagonal,_page "".
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.