Grid Capture

Instructions

Two players compete on an n x n map grid, where each cell is 'X', 'O', or '.' (unclaimed). Place player (either 'X' or 'O') on the empty cell (row, col). In each of the 8 directions, if one or more consecutive opponent cells are immediately followed by a player cell, all of them are captured and become player.

Return the map after the claim. If (row, col) is out of bounds, already claimed, or the claim captures no cells, return grid unchanged.

Example 1:

Input:  grid = ["....",
                ".OX.",
                ".XO.",
                "...."], row = 1, col = 0, player = "X"
Output: ["....",
         "XXX.",
         ".XO.",
         "...."]

Explanation: The O at (1,1) lies between the new X and the X at (1,2), so it is captured.

Example 2:

Input:  grid = ["...",
                ".O.",
                "..X"], row = 0, col = 0, player = "X"
Output: ["X..",
         ".X.",
         "..X"]

Explanation: The O at (1,1) is captured diagonally by the X at (2,2).

Constraints:

  • 1 <= n <= 100

Function Signature

from typing import List

def captureGrid(grid: List[str], row: int, col: int, player: str) -> List[str]:
    pass