Implement the findWinnerTicTacToeRow method that returns the winner found in any complete row of a tic-tac-toe board.
The input contains a Tic-Tac-Toe board board and its size n. The board contains player marks such as X and O, and empty cells are represented by E.
Your task is to return the player mark that has completed a full row, full column, or full diagonal. A player wins when all cells in one of these lines contain the same non-empty mark.
For example, in [[X,X,X],[O,O,E],[E,E,E]], the first row contains only X, so the result is X.
Check every possible winning line on the board.
First check each row, then each column. For a line to be a winning line, its first cell must not be E, and every other cell in that line must be equal to it.
Finally, check both diagonals using the same rule. Return the winning mark as soon as it is found. If no winning line exists, return E as the no-winner value.
Pseudocode:
function findWinnerTicTacToeRow(board, n):
for each row r:
if board[r][0] != E and every cell in row r equals board[r][0]:
return board[r][0]
for each column c:
if board[0][c] != E and every cell in column c equals board[0][c]:
return board[0][c]
if board[0][0] != E and every main diagonal cell is equal:
return board[0][0]
if board[0][n - 1] != E and every opposite diagonal cell is equal:
return board[0][n - 1]
return E