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. · לחץ על הרץ כדי לראות את התוצא כאן.