{"record":{"id":"2ceb1e810ce9ddbb","repo":"Unity-Technologies/ml-agents","slug":"col-was-col-but-must-be-between-0-and-maxboard","errorCode":null,"errorMessage":"col was {col}, but must be between 0 and {maxBoardSize.Columns - 1}.","messagePattern":"col was (.+?), but must be between 0 and (.+?)\\.","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs","lineNumber":161,"sourceCode":"        /// <summary>\n        /// Construct a Move from the row, column, direction, and board size.\n        /// </summary>\n        /// <param name=\"row\">Row</param>\n        /// <param name=\"col\">Col</param>\n        /// <param name=\"dir\">Dir</param>\n        /// <param name=\"maxBoardSize\">Max board size</param>\n        /// <returns>Corresponding `Move`.</returns>\n        public static Move FromPositionAndDirection(int row, int col, Direction dir, BoardSize maxBoardSize)\n        {\n            // Check for out-of-bounds\n            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;","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs#L143-L179","documentation":"Same bounds check as the row variant but for the column: Move.FromPositionAndDirection throws IndexOutOfRangeException when col is negative or >= maxBoardSize.Columns. The Move API requires the source cell to exist on the board before direction normalization.","triggerScenarios":"Calling Move.FromPositionAndDirection with col < 0 or col >= maxBoardSize.Columns — typically unvalidated agent action output or transposed row/col arguments.","commonSituations":"Passing (col, row) in the wrong order; agents emitting raw unclamped action indices; mismatch between the passed maxBoardSize and the real board size.","solutions":["Validate/clamp col against board.Columns before constructing the move","Verify argument order — FromPositionAndDirection takes (row, col, dir, maxBoardSize)","Generate moves via board.CheckMove or iterate legal moves instead of constructing raw coordinates"],"exampleFix":"// before\nvar move = Move.FromPositionAndDirection(x, y, dir, board.MaxBoardSize); // x,y swapped\n// after\nvar move = board.CheckMove(y, x, dir); // row=y, col=x, null-checked","handlingStrategy":"validation","validationCode":"bool CanPlace(int row, int col, BoardSize size) =>\n    row >= 0 && row < size.Rows && col >= 0 && col < size.Columns;\n// validate col before: if (col < 0 || col >= board.MaxBoardSize.Columns) retry;","typeGuard":"bool IsValidCol(int col, BoardSize size) => col >= 0 && col < size.Columns;","tryCatchPattern":"try { var move = Move.FromPositionAndDirection(row, col, dir, board.MaxBoardSize); }\ncatch (IndexOutOfRangeException e) when (e.Message.StartsWith(\"col was\"))\n{ col = Mathf.Clamp(col, 0, board.MaxBoardSize.Columns - 1); }","preventionTips":["Clamp column coordinates from action outputs","Verify (row, col) parameter order — it is row first","Use board.CheckMove which returns null for invalid input instead of throwing"],"tags":["unity","ml-agents","match3","index-out-of-range","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"}