Precompute Distances + BitMask DP + MiniMax Algo
javascript []\nconst KNIGHT_MOVES = [\n  [-2, -1], [-2, 1], [-1, -2], [-1, 2],\n  [1, -2], [1, 2], [2, -1], [2, 1]\n];\n\n/**\n * @param {number} kx - Knight\'s
```javascript []\nconst KNIGHT_MOVES = [\n  [-2, -1], [-2, 1], [-1, -2], [-1, 2],\n  [1, -2], [1, 2], [2, -1], [2, 1]\n];\n\n/**\n * @param {number} kx - Knight\'s initial x position\n * @param {number} ky - Knight\'s initial y position\n * @param {number[][]} positions - Array of pawn positions\n * @return {number} Maximum moves Alice can achieve\n */\nconst maxMoves = (kx, ky, positions) => {\n  const n = positions.length;\n  const distances = Array.from({ length: n + 1 }, () => Array(n + 1).fill(0));\n  const memo = Array.from({ length: n + 1 }, () => Array(1 << n).fill(null));\n\n  // Precompute distances between all positions\n  for (let i = 0; i < n; i++) {\n    distances[n][i] = calculateMoves(kx, ky, positions[i][0], positions[i][1]);\n    for (let j = i + 1; j < n; j++) {\n      const dist = calculateMoves(\n        positions[i][0], positions[i][1],\n        positions[j][0], positions[j][1]\n      );\n      distances[i][j] = distances[j][i] = dist;\n    }\n  }\n\n  return minimax(n, (1 << n) - 1, true, distances, memo);\n};\n\n/**\n * Minimax function to calculate optimal moves\n * @param {number} lastPos\n * @param {number} remainingPawns\n * @param {boolean} isAlice\n * @param {number[][]} distances\n * @param {Array<Array<null|number>>} memo\n * @return {number}\n */\nconst minimax = (lastPos, remainingPawns, isAlice, distances, memo) => {\n  if (remainingPawns === 0) return 0;\n  if (memo[lastPos][remainingPawns] !== null) return memo[lastPos][remainingPawns];\n\n  const n = distances.length - 1;\n  let result = isAlice ? 0 : Infinity;\n\n  for (let i = 0; i < n; i++) {\n    if ((remainingPawns & (1 << i)) !== 0) {\n      const newRemainingPawns = remainingPawns & ~(1 << i);\n      const moveValue = distances[lastPos][i] + minimax(i, newRemainingPawns, !isAlice, distances, memo);\n\n      result = isAlice ? Math.max(result, moveValue) : Math.min(result, moveValue);\n    }\n  }\n\n  memo[lastPos][remainingPawns] = result;\n  return result;\n};\n\n/**\n * Calculate the minimum moves for the knight to reach a target position using BFS\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @return {number}\n */\nconst calculateMoves = (x1, y1, x2, y2) => {\n  if (x1 === x2 && y1 === y2) return 0;\n\n  const visited = Array.from({ length: 50 }, () => Array(50).fill(false));\n  const queue = [[x1, y1, 0]];\n  visited[x1][y1] = true;\n\n  while (queue.length > 0) {\n    const [x, y, moves] = queue.shift();\n\n    for (const [dx, dy] of KNIGHT_MOVES) {\n      const nx = x + dx, ny = y + dy;\n      if (nx === x2 && ny === y2) return moves + 1;\n      if (nx >= 0 && nx < 50 && ny >= 0 && ny < 50 && !visited[nx][ny]) {\n        queue.push([nx, ny, moves + 1]);\n        visited[nx][ny] = true;\n      }\n    }\n  }\n}\n```
['Array', 'Math', 'Bit Manipulation', 'Breadth-First Search', 'Game Theory', 'Bitmask', 'JavaScript']