Solution Minimum Moves to Reach Target with Rotations
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```\nclass Solution {\n    function minimumMoves($grid) {\n        $q = new SplQueue();\n        $n = count($grid);\n        $v = array_fill(0, $n, array_fill(0, $n, array_fill(0, 2, false)));\n        $q->enqueue([0, 1, 0]);\n        $v[0][1][0] = true;\n        $res = 0;\n        \n        while (!$q->isEmpty()) {\n            $count = $q->count();\n            for ($i = 0; $i < $count; $i++) {\n                [$r, $c, $d] = $q->dequeue();\n                if ($r === $n - 1 && $c === $n - 1 && $d === 0) return $res;\n                \n                if ($d === 0) {\n                    if ($c + 1 < $n && $grid[$r][$c + 1] === 0) $this->add($q, $r, $c + 1, 0, $v);\n                    if ($r + 1 < $n && $grid[$r + 1][$c] === 0 && $grid[$r + 1][$c - 1] === 0) {\n                        $this->add($q, $r + 1, $c, 0, $v);\n                        $this->add($q, $r + 1, $c - 1, 1, $v);\n                    }\n                } else {\n                    if ($r + 1 < $n && $grid[$r + 1][$c] === 0) $this->add($q, $r + 1, $c, 1, $v);\n                    if ($c + 1 < $n && $grid[$r][$c + 1] === 0 && $grid[$r - 1][$c + 1] === 0) {\n                        $this->add($q, $r, $c + 1, 1, $v);\n                        $this->add($q, $r - 1, $c + 1, 0, $v);\n                    }\n                }\n            }\n            $res++;\n        }\n        return -1;\n    }\n\n    function add(&$q, $r, $c, $d, &$v) {\n        if (!$v[$r][$c][$d]) {\n            $q->enqueue([$r, $c, $d]);\n            $v[$r][$c][$d] = true;\n        }\n    }\n}\n\n```
['PHP']