Apply a Reversi Move
Problem statement
Given a Reversi board board, a zero-based target cell row, col, and a player player equal to B or W, apply exactly one move.
A direction captures pieces when one or more consecutive opponent pieces start next to the target and are followed, in that same direction, by one of the current player's pieces. A legal move places the player's piece and flips every captured line in all eight directions.
If the target is occupied or no direction captures an opponent piece, return the original board unchanged. Do not modify the input strings.
Function
applyReversiMove(board: String[], row: int, col: int, player: char) → String[]Examples
Example 1
board = ["....",".WB.","...."]row = 1col = 3player = "W"return = ["....",".WWW","...."]The new white piece at column 3 brackets the black piece with the existing white piece at column 1.
Example 2
board = ["..B..","..W..","BW.WB","..W..","..B.."]row = 2col = 2player = "B"return = ["..B..","..B..","BBBBB","..B..","..B.."]The move captures one white piece in each cardinal direction.
Example 3
board = ["...","...","..."]row = 1col = 1player = "B"return = ["...","...","..."]No opponent line is bracketed, so the move is invalid and the board remains unchanged.
Constraints
1 <= board.length, board[i].length <= 50.- Every row has the same length and contains only
.,B, orW. 0 <= row < board.lengthand0 <= col < board[0].length.playerisBorW.