{"record":{"id":"bf3220bdd3f854d4","repo":"TheAlgorithms/Python","slug":"move-is-out-of-bounds-for-a-matrix","errorCode":null,"errorMessage":"Move is out of bounds for a matrix.","messagePattern":"Move is out of bounds for a matrix\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"matrix/matrix_based_game.py","lineNumber":102,"sourceCode":"    for row in matrix:\n        if len(row) != size:\n            msg = f\"Each row in the matrix must have exactly {size} characters.\"\n            raise ValueError(msg)\n        if not all(char.isalnum() for char in row):\n            raise ValueError(\"Matrix rows can only contain letters and numbers.\")\n\n\ndef validate_moves(moves: list[tuple[int, int]], size: int) -> None:\n    \"\"\"\n    >>> validate_moves([(1, 2), (-1, 0)], 3)\n    Traceback (most recent call last):\n        ...\n    ValueError: Move is out of bounds for a matrix.\n    \"\"\"\n    for move in moves:\n        x, y = move\n        if not (0 <= x < size and 0 <= y < size):\n            raise ValueError(\"Move is out of bounds for a matrix.\")\n\n\ndef parse_moves(input_str: str) -> list[tuple[int, int]]:\n    \"\"\"\n    >>> parse_moves(\"0 1, 1 1\")\n    [(0, 1), (1, 1)]\n    >>> parse_moves(\"0 1, 1 1, 2\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Each move must have exactly two numbers.\n    >>> parse_moves(\"0 1, 1 1, 2 4 5 6\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Each move must have exactly two numbers.\n    \"\"\"\n    moves = []\n    for pair in input_str.split(\",\"):\n        parts = pair.strip().split()","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/matrix/matrix_based_game.py#L84-L120","documentation":"Error \"Move is out of bounds for a matrix.\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at matrix/matrix_based_game.py:102 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a move whose coordinates lie within the matrix dimensions."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}