-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.py
More file actions
39 lines (34 loc) · 1.47 KB
/
Copy pathprocessor.py
File metadata and controls
39 lines (34 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import List, Dict, Any, Union, Optional
class GameStateProcessor:
def __init__(self, entities: List[Dict[str, Any]]) -> None:
self.entities = entities
def get_active_players(self, min_health: int = 1) -> List[Dict[str, Any]]:
"""
Filters entities list returning only living players.
Uses a generator expression for memory-efficient iteration.
"""
return [e for e in self.entities if e.get('type') == 'player' and e.get('hp', 0) >= min_health]
def calculate_entity_density(self, area_volume: float) -> float:
"""
Calculates distribution ratio of entities within defined volume.
Raises ValueError if volume is non-positive.
"""
if area_volume <= 0:
raise ValueError("Spatial volume must be a positive scalar.")
return len(self.entities) / area_volume
def augment_state(self, key: str, value: Any) -> None:
"""
Injects metadata into all managed entities dynamically.
"""
for entity in self.entities:
entity[key] = value
def process_collision_batch(events: List[Dict[str, Union[int, str]]]) -> Dict[str, int]:
"""
Aggregates collision types from a raw event stream.
Returns a frequency map of collision impact levels.
"""
summary: Dict[str, int] = {}
for event in events:
impact = str(event.get('severity', 'minor'))
summary[impact] = summary.get(impact, 0) + 1
return summary