{"record":{"id":"fb3539ea27582453","repo":"Unity-Technologies/ml-agents","slug":"cannot-move-cell-at-row-row-col-col-in-directi","errorCode":null,"errorMessage":"Cannot move cell at row={row} col={col} in Direction={dir}","messagePattern":"Cannot move cell at row=(.+?) col=(.+?) in Direction=(.+?)","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs","lineNumber":172,"sourceCode":"            if (row < 0 || row >= maxBoardSize.Rows)\n            {\n                throw new IndexOutOfRangeException($\"row was {row}, but must be between 0 and {maxBoardSize.Rows - 1}.\");\n            }\n\n            if (col < 0 || col >= maxBoardSize.Columns)\n            {\n                throw new IndexOutOfRangeException($\"col was {col}, but must be between 0 and {maxBoardSize.Columns - 1}.\");\n            }\n\n            // Check moves that would go out of bounds e.g. col == 0 and dir == Left\n            if (\n                row == 0 && dir == Direction.Down ||\n                row == maxBoardSize.Rows - 1 && dir == Direction.Up ||\n                col == 0 && dir == Direction.Left ||\n                col == maxBoardSize.Columns - 1 && dir == Direction.Right\n            )\n            {\n                throw new IndexOutOfRangeException($\"Cannot move cell at row={row} col={col} in Direction={dir}\");\n            }\n\n            // Normalize - only consider Right and Up\n            if (dir == Direction.Left)\n            {\n                dir = Direction.Right;\n                col = col - 1;\n            }\n            else if (dir == Direction.Down)\n            {\n                dir = Direction.Up;\n                row = row - 1;\n            }\n\n            int moveIndex;\n            if (dir == Direction.Right)\n            {\n                moveIndex = col + row * (maxBoardSize.Columns - 1);","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs#L154-L190","documentation":"After confirming the cell is in bounds, FromPositionAndDirection checks whether the swap in the requested direction would push a cell outside the board (e.g. moving Left from column 0). Such a move is impossible, so it throws IndexOutOfRangeException even though the coordinates themselves were valid. Note that Left/Up moves are later normalized to Right/Up, so only edge-adjacent cells in the move direction are rejected.","triggerScenarios":"Requesting Direction.Left from col == 0, Direction.Right from col == Columns-1, Direction.Down from row == 0, or Direction.Up from row == Rows-1 while the move would go out of bounds.","commonSituations":"Agents randomly sampling directions at board edges; heuristic policies that don't prune edge moves; replayed action logs produced on a differently sized board.","solutions":["Filter illegal edge moves before calling FromPositionAndDirection (use board.CheckMove, which returns null instead of throwing)","Enumerate Move.GetValidMoves / valid move lists for the cell and pick from those","Clamp direction: rewrite Left→Right on the adjacent cell pair so the swap stays in bounds"],"exampleFix":"// before\nvar move = Move.FromPositionAndDirection(0, 3, Direction.Left, board.MaxBoardSize); // throws\n// after\nvar move = board.CheckMove(0, 3, Direction.Left); // returns null (or swap representation)\nif (move != null) { /* apply */ }","handlingStrategy":"validation","validationCode":"bool CanShift(int row, int col, Direction dir, BoardSize s) =>\n    !(row == 0 && dir == Direction.Down) &&\n    !(row == s.Rows - 1 && dir == Direction.Up) &&\n    !(col == 0 && dir == Direction.Left) &&\n    !(col == s.Columns - 1 && dir == Direction.Right);\n// check before calling FromPositionAndDirection","typeGuard":null,"tryCatchPattern":"try { var move = Move.FromPositionAndDirection(row, col, dir, board.MaxBoardSize); }\ncatch (IndexOutOfRangeException e) when (e.Message.Contains(\"Cannot move cell\"))\n{ /* skip this action / sample another direction */ }","preventionTips":["Use board.CheckMove or Move.GetValidMoves instead of constructing moves from raw coordinates","Prune edge-direction combinations when sampling actions at board borders","Remember Left/Up are normalized to Right/Up — encode moves on the in-bounds side of the pair"],"tags":["unity","ml-agents","match3","index-out-of-range","edge-move","bounds"],"backgroundTag":"grid-coordinate-out-of-bounds","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}