Spaces:
Sleeping
Sleeping
Create rules/lbw_engine.py
Browse files- rules/lbw_engine.py +23 -0
rules/lbw_engine.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Implements ICC LBW rules & umpire‑call margin."""
|
2 |
+
|
3 |
+
from typing import Dict
|
4 |
+
|
5 |
+
|
6 |
+
class LBWEngine:
|
7 |
+
def __init__(self, margin_mm: float = 20.0):
|
8 |
+
self.margin = margin_mm
|
9 |
+
|
10 |
+
def decide(self, event_meta: Dict):
|
11 |
+
"""Return verdict ('OUT', 'NOT OUT', 'UMPIRE CALL') with reasoning."""
|
12 |
+
pitch_zone = event_meta["pitch_zone"] # 'inline', 'outside_off', 'outside_leg'
|
13 |
+
impact_zone = event_meta["impact_zone"]
|
14 |
+
projected_hit = event_meta["hits_stumps"] # bool
|
15 |
+
|
16 |
+
if pitch_zone == "outside_leg":
|
17 |
+
return "NOT OUT", "Ball pitched outside leg"
|
18 |
+
if impact_zone != "in_line":
|
19 |
+
return "NOT OUT", "Impact outside off and shot offered" if event_meta.get("shot_offered") else "NOT OUT"
|
20 |
+
if projected_hit:
|
21 |
+
return "OUT", "All three criteria satisfied"
|
22 |
+
else:
|
23 |
+
return "UMPIRE CALL", "Missing stumps within margin"
|