Java Concise BFS Solution - with comments
Java\nclass Solution {\n    public int minimumMoves(int[][] grid) {\n        int n = grid.length;\n        int res = 0;\n        int[][] start = {{0, 0}, {0, 1}
```Java\nclass Solution {\n    public int minimumMoves(int[][] grid) {\n        int n = grid.length;\n        int res = 0;\n        int[][] start = {{0, 0}, {0, 1}};\n        Queue<int[][]> q = new LinkedList<>();\n        Set<String> visited = new HashSet<>();\n        q.add(start);\n        visited.add(toString(start));\n        while (!q.isEmpty()) {\n            for (int size = q.size(); size > 0; size--) {\n                int[][] cur = q.poll();\n                if (cur[0][0] == n - 1 && cur[0][1] == n - 2 && cur[1][0] == n - 1 && cur[1][1] == n - 1) return res;\n                int[] tail = cur[0], head = cur[1];\n                int x = tail[0], y = tail[1];\n                if (tail[0] == head[0]) { // horizontal\n                    if (x < n - 1 && grid[x+1][y] == 0 && grid[x+1][y+1] == 0) {\n                        int[][] down = {{x + 1, y}, {x + 1, y + 1}}; // down\n                        int[][] turn = {{x, y}, {x + 1, y}}; // clockwise\n                        if (visited.add(toString(down))) q.offer(down);\n                        if (visited.add(toString(turn))) q.offer(turn);\n                    }\n                    if (y + 2 < n && grid[x][y+2] == 0) {\n                        int[][] right = {{x, y + 1}, {x, y + 2}}; // right\n                        if (visited.add(toString(right))) q.offer(right);\n                    } \n                } else { // vertical\n                    if (y < n - 1 && grid[x][y+1] == 0 && grid[x+1][y+1] == 0) {\n                        int[][] right = {{x, y + 1}, {x + 1, y + 1}}; // right\n                        int[][] turn = {{x,y}, {x, y + 1}}; // counterclockwise\n                        if (visited.add(toString(right))) q.offer(right);\n                        if (visited.add(toString(turn))) q.offer(turn);\n                    }\n                    \n                    if (x + 2 < n && grid[x+2][y] == 0) {\n                        int[][] down = {{x+1, y}, {x+2, y}}; // down\n                        if (visited.add(toString(down))) q.offer(down);\n                    }\n                }\n            }\n            res++;\n        }\n        return -1;\n    }\n    \n    private String toString(int[][] pos) {\n        return pos[0][0] + ":" + pos[0][1] + ":" + pos[1][0] + ":" + pos[1][1];\n    }\n}\n```
[]