{"record":{"id":"7a2cdba65997db73","repo":"TheAlgorithms/Python","slug":"depth-cannot-be-less-than-0","errorCode":null,"errorMessage":"Depth cannot be less than 0","messagePattern":"Depth cannot be less than 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backtracking/minimax.py","lineNumber":56,"sourceCode":"    >>> height = math.log(len(scores), 2)\n    >>> minimax(0, 0, True, scores, height)\n    65\n    >>> minimax(-1, 0, True, scores, height)\n    Traceback (most recent call last):\n        ...\n    ValueError: Depth cannot be less than 0\n    >>> minimax(0, 0, True, [], 2)\n    Traceback (most recent call last):\n        ...\n    ValueError: Scores cannot be empty\n    >>> scores = [3, 5, 2, 9, 12, 5, 23, 23]\n    >>> height = math.log(len(scores), 2)\n    >>> minimax(0, 0, True, scores, height)\n    12\n    \"\"\"\n\n    if depth < 0:\n        raise ValueError(\"Depth cannot be less than 0\")\n    if len(scores) == 0:\n        raise ValueError(\"Scores cannot be empty\")\n\n    # Base case: If the current depth equals the height of the tree,\n    # return the score of the current node.\n    if depth == height:\n        return scores[node_index]\n\n    # If it's the maximizer's turn, choose the maximum score\n    # between the two possible moves.\n    if is_max:\n        return max(\n            minimax(depth + 1, node_index * 2, False, scores, height),\n            minimax(depth + 1, node_index * 2 + 1, False, scores, height),\n        )\n\n    # If it's the minimizer's turn, choose the minimum score\n    # between the two possible moves.","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/backtracking/minimax.py#L38-L74","documentation":"Raised by casimir_force() in physics/casimir_effect.py when the plate area argument is negative. Area enters the force/area/distance relations linearly, and a negative plate area is physically impossible, so it is rejected. It is the last of the three per-argument negativity checks.","triggerScenarios":"casimir_force(force=0, area=-0.0023, distance=0.0023746); passing an area computed as a signed determinant/cross-product result that went negative.","commonSituations":"Area computed geometrically (e.g. from vectors) where the sign depends on vertex ordering; passing -1 or other negative sentinels for 'unknown' fields.","solutions":["Take abs() of the computed area if the sign is a geometric artifact.","Validate area >= 0 before the call.","Ensure exactly one argument is 0 and the others are positive reals."],"exampleFix":"# before\ncasimir_force(force=2737e-21, area=signed_area, distance=0.0023746)\n\n# after\ncasimir_force(force=2737e-21, area=abs(signed_area), distance=0.0023746)","handlingStrategy":"validation","validationCode":"if area < 0:\n    area = abs(area)  # geometric sign artifact\ncasimir_force(force=f, area=area, distance=d)","typeGuard":null,"tryCatchPattern":"try:\n    casimir_force(force=f, area=a, distance=d)\nexcept ValueError as e:\n    if \"Area\" in str(e):\n        casimir_force(force=f, area=abs(a), distance=d)\n    else:\n        raise","preventionTips":["Normalize polygon-vertex ordering before computing areas.","Area is checked last — fix force/distance first if multiple negatives.","Never use negative sentinels for plate area."],"tags":["physics","input-validation","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}