"""Typed, observational breakpoints. Never call AI eligibility or score functions.""" import math FIELDS={ 'player_health_below': {'kind','value'}, 'player_dead': {'kind'}, 'event': {'kind','event_kind'}, 'input_ready': {'kind','value'}, 'actor_dead': {'kind','generation','actor_id'}, 'actor_health_below': {'kind','generation','actor_id','value'}, 'actor_attacking': {'kind','generation','actor_id','value'}, 'distance_below': {'kind','generation','actor_id','value'}, } def validate(c): if not isinstance(c,dict) or c.get('kind') not in FIELDS or set(c)!=FIELDS[c['kind']]: raise ValueError('unsupported_condition: expected one of '+', '.join(FIELDS)+' with its documented fields') if 'generation' in c: for field in ('generation','actor_id'): if type(c[field]) is not int or not 0<=c[field]<=2147483646: raise ValueError(field+' must be a nonnegative native integer') if c['kind'] in ('input_ready','actor_attacking'): if type(c['value']) is not bool: raise ValueError('condition value must be boolean') elif 'value' in c: if type(c['value']) not in (int,float) or not math.isfinite(c['value']) or c['value']<0: raise ValueError('threshold must be finite and nonnegative') if c['kind']=='event' and c['event_kind'] not in ('attempt','contact'): raise ValueError('event_kind must be attempt or contact') def required(obj,key): if key not in obj or obj[key] is None: raise ValueError('unsupported_condition: required field unavailable: '+key) return obj[key] def evaluate(c,snapshot,events,call): validate(c); kind=c['kind'] if kind=='event': return next((e for e in events if e.get('kind')==c['event_kind']),None) world=required(snapshot['data'],'world'); player=required(world,'player') if kind=='player_dead': return required(player,'alive') is False if kind=='player_health_below': return required(player,'hp')