Easy Java Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public static int[] x_axis = {2, 2, -2, -2, 1, 1, -1, -1};\n    public static int[] y_axis = {1, -1, 1, -1, -2, 2, -2, 2};\n    public static int[][][][] predis;\n    public static Integer[][][] dp;\n    public static boolean flag = false;\n    public int maxMoves(int kx, int ky, int[][] positions) {\n        int n = positions.length;\n        int[][] p = new int[n + 1][2];\n        p[0][0] = kx;\n        p[0][1] = ky;\n        for(int i = 1; i <= n; i++) {\n            p[i][0] = positions[i - 1][0];\n            p[i][1] = positions[i - 1][1];\n        }\n        if(!flag) {\n            predis = new int[50][50][50][50];\n            for(int i = 0; i < 50; i++) {\n                for(int j = 0; j < 50; j++) {\n                    for(int k = 0; k < 50; k++) {\n                        Arrays.fill(predis[i][j][k], -1);\n                    }\n                }\n            }\n            for(int i = 0; i < 50; i++) {\n                for(int j = 0; j < 50; j++) {\n                    dfs(i, j);\n                }\n            }\n            flag = true;\n        }\n        int mask = (1 << n) - 1;\n        dp = new Integer[51][1 << n][2];\n        int ans = dp(p, mask, 0, 1);\n        return ans;\n    }\n    public static int dp(int[][] p, int mask, int last, int chance) {\n        if(mask == 0) {\n            return 0;\n        }\n        if(dp[last][mask][chance] != null) {\n            return dp[last][mask][chance];\n        }\n        int ans = chance == 1 ? 0 : (int) 1e9;\n        for(int i = 1; i < p.length; i++) {\n            int l = (1 << (i - 1));\n            if((mask & l) > 0) {\n                if(chance == 1) {\n                    ans = Math.max(ans, predis[p[last][0]][p[last][1]][p[i][0]][p[i][1]] + dp(p, mask ^ l, i, 1 - chance));\n                } else {\n                    ans = Math.min(ans, predis[p[last][0]][p[last][1]][p[i][0]][p[i][1]] + dp(p, mask ^ l, i, 1 - chance));\n                }\n            }\n        }\n        return dp[last][mask][chance] = ans;\n    }\n\n    public static void dfs(int k1, int k2) {\n        Queue<int[]> q = new LinkedList<>();\n        q.add(new int[]{k1, k2});\n        int[][] mat = new int[50][50];\n        for(int i = 0; i < 50; i++) {\n            Arrays.fill(mat[i], (int) -1);\n        }\n        predis[k1][k2][k1][k2] = 0;\n        while(!q.isEmpty()) {\n            int[] l = q.poll();\n            for(int i = 0; i < 8; i++) {\n                int u = l[0] + x_axis[i];\n                int v = l[1] + y_axis[i];\n                if(u < 0 || v < 0 || u >= 50 || v >= 50) continue;\n                if(predis[k1][k2][u][v] == -1) {\n                    predis[k1][k2][u][v] = predis[k1][k2][l[0]][l[1]] + 1;\n                    q.add(new int[]{u, v});\n                }\n            }\n        }\n    }\n}\n```
['Java']