JS
Code\n\n/* ----------------------------------------------- */\n/*  Template by Bharadwaj ( The Authentic JS CodeBuff )  */\n/* ---------------------------------
# Code\n```\n/* ----------------------------------------------- */\n/*  Template by Bharadwaj ( The Authentic JS CodeBuff )  */\n/* ------------------------------------------------ */\n/*    Youtube: https://youtube.com/@code-with-Bharadwaj   */\n/*    Portfolio: https://manu-bharadwaj-portfolio.vercel.app/ */\n/* ----------------------------------------------- */\n\nvar maxMoves = function(startX, startY, targets) {\n    let knightPosition = [startX, startY];\n    let positionsList = targets.map(([x, y]) => [x, y]);\n    let numTargets = positionsList.length;\n    let distances = new Map();\n\n    let movePatterns = [[-2, -1], [-2, 1], [-1, -2], [-1, 2], [1, -2], [1, 2], [2, -1], [2, 1]];\n\n    function calculateDistance(from, to) {\n        let sortedFrom = from[0] < to[0] ? from : to;\n        let sortedTo = from[0] < to[0] ? to : from;\n        let key = `${sortedFrom[0]},${sortedFrom[1]}-${sortedTo[0]},${sortedTo[1]}`;\n        \n        if (distances.has(key)) {\n            return distances.get(key);\n        }\n\n        let [startX, startY] = sortedFrom;\n        let [endX, endY] = sortedTo;\n        let grid = Array.from({ length: 50 }, () => Array(50).fill(-1));\n        grid[startX][startY] = 0;\n        let queue = [[startX, startY]];\n        let idx = 0;\n\n        while (idx < queue.length) {\n            let [curX, curY] = queue[idx++];\n            for (let [dx, dy] of movePatterns) {\n                let newX = curX + dx;\n                let newY = curY + dy;\n                if (newX >= 0 && newY >= 0 && newX < 50 && newY < 50 && grid[newX][newY] === -1) {\n                    grid[newX][newY] = grid[curX][curY] + 1;\n                    if (newX === endX && newY === endY) {\n                        distances.set(key, grid[newX][newY]);\n                        return grid[newX][newY];\n                    }\n                    queue.push([newX, newY]);\n                }\n            }\n        }\n        distances.set(key, -1);\n        return -1;\n    }\n\n    let memoAlice = new Map();\n    let memoBob = new Map();\n    let fullMask = (1 << numTargets) - 1;\n\n    function computeAlice(mask, position) {\n        if (mask === 0) return 0;\n        let memoKey = `${mask}-${position}`;\n        if (memoAlice.has(memoKey)) {\n            return memoAlice.get(memoKey);\n        }\n        let bestOutcome = 0;\n        for (let i = 0; i < numTargets; i++) {\n            if (mask & (1 << i)) {\n                let newMask = mask ^ (1 << i);\n                bestOutcome = Math.max(bestOutcome, computeBob(newMask, i) + calculateDistance(positionsList[position], positionsList[i]));\n            }\n        }\n        memoAlice.set(memoKey, bestOutcome);\n        return bestOutcome;\n    }\n\n    function computeBob(mask, position) {\n        if (mask === 0) return 0;\n        let memoKey = `${mask}-${position}`;\n        if (memoBob.has(memoKey)) {\n            return memoBob.get(memoKey);\n        }\n        let bestOutcome = Infinity;\n        for (let i = 0; i < numTargets; i++) {\n            if (mask & (1 << i)) {\n                let newMask = mask ^ (1 << i);\n                bestOutcome = Math.min(bestOutcome, computeAlice(newMask, i) + calculateDistance(positionsList[position], positionsList[i]));\n            }\n        }\n        memoBob.set(memoKey, bestOutcome);\n        return bestOutcome;\n    }\n\n    let result = 0;\n    for (let i = 0; i < numTargets; i++) {\n        let remainingMask = fullMask ^ (1 << i);\n        result = Math.max(result, computeBob(remainingMask, i) + calculateDistance(positionsList[i], knightPosition));\n    }\n    return result;\n};\n\n\n\n```
['JavaScript']