Short and straightforward
Code\npython3 []\nfrom collections import deque\n\nclass Solution:\n    @functools.cache\n    def get_moves(self, kx, ky, x, y):\n        """This function finds
# Code\n```python3 []\nfrom collections import deque\n\nclass Solution:\n    @functools.cache\n    def get_moves(self, kx, ky, x, y):\n        """This function finds minimum moves to capture pawn at position from kx, ky"""\n        q = deque()\n        q.append((kx, ky, 0))\n        visited = set()\n        while q:\n            for _ in range(len(q)):\n                cx, cy, moves = q.popleft()\n                if cx == x and cy == y:\n                    return moves\n                # 8 possible directions for the knight\n                directions = [(1,2),(-1,2),(1,-2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1)]\n                for dx, dy in directions:\n                    if 0 <= cx + dx < 50 and 0 <= cy + dy < 50 and (cx + dx, cy + dy) not in visited:\n                        q.append((cx + dx, cy + dy, moves + 1))\n                        visited.add((cx + dx, cy + dy))\n                        \n    def maxMoves(self, kx: int, ky: int, positions: List[List[int]]) -> int:\n\n        @functools.cache\n        def dfs(kx, ky, pawns, aliceTurn):\n\n            if pawns == (1 << len(positions)) - 1:\n                return 0  # No more moves to make\n\n            func = max if aliceTurn else min\n            ans = -math.inf if aliceTurn else math.inf\n            for i in range(len(positions)):\n                curr_mask = 1 << i\n                if pawns & curr_mask:\n                    # If alreaady captured\n                    continue\n                nx, ny = positions[i]\n                min_moves = self.get_moves(kx, ky, nx, ny)\n                ans = func(ans, min_moves + dfs(nx, ny, pawns | curr_mask, 1 - aliceTurn))\n\n            return ans\n        \n        return dfs(kx, ky, 0, 1)\n```
['Python3']