@@ -52,31 +52,31 @@ Pure data containers that define entity properties and state.
5252``` python
5353class HealthComponent (Component ):
5454 """ Manages agent health and damage tracking."""
55-
55+
5656 def __init__ (self , max_health : int = 100 ):
5757 self .max_health = max_health
5858 self .current_health = max_health
5959 self .last_damage_tick = 0
6060 self .damage_history: List[int ] = []
61-
61+
6262 @ property
6363 def health_percentage (self ) -> float :
6464 """ Current health as percentage of maximum."""
6565 return self .current_health / self .max_health
66-
66+
6767 @ property
6868 def is_critical (self ) -> bool :
6969 """ True if health is below 25% of maximum."""
7070 return self .health_percentage < 0.25
71-
71+
7272 def to_dict (self ) -> Dict[str , Any]:
7373 return {
7474 " max_health" : self .max_health,
7575 " current_health" : self .current_health,
7676 " last_damage_tick" : self .last_damage_tick,
7777 " damage_history" : self .damage_history
7878 }
79-
79+
8080 def validate (self , entity_id : str ) -> Tuple[bool , List[str ]]:
8181 errors = []
8282 if self .current_health < 0 :
@@ -141,19 +141,19 @@ The provider pattern bridges the gap between world-agnostic cognitive systems an
141141``` python
142142class VitalityMetricsProvider (VitalityMetricsProviderInterface ):
143143 """ Bridges health/energy systems with cognitive architecture."""
144-
144+
145145 def get_normalized_vitality_metrics (
146- self ,
147- entity_id : str ,
148- components : Dict[Type[Component], Component],
146+ self ,
147+ entity_id : str ,
148+ components : Dict[Type[Component], Component],
149149 config : Dict[str , Any]
150150 ) -> Dict[str , float ]:
151151 health_comp = components.get(HealthComponent)
152152 energy_comp = components.get(EnergyComponent)
153-
153+
154154 if not health_comp or not energy_comp:
155155 return {" health_norm" : 0.5 , " energy_norm" : 0.5 , " fatigue_norm" : 0.5 }
156-
156+
157157 return {
158158 " health_norm" : health_comp.current / health_comp.max_health,
159159 " energy_norm" : energy_comp.current / energy_comp.max_energy,
@@ -214,38 +214,38 @@ The parent class for all simulation systems, providing event bus access and life
214214``` python
215215class ExampleSystem (System ):
216216 """ Example system demonstrating best practices."""
217-
217+
218218 def __init__ (self , simulation_state , config , cognitive_scaffold ):
219219 super ().__init__ (simulation_state, config, cognitive_scaffold)
220-
220+
221221 # Subscribe to relevant events
222222 if self .event_bus:
223223 self .event_bus.subscribe(" target_event" , self .handle_event)
224224 self .event_bus.subscribe(" tick_completed" , self .on_tick_complete)
225-
225+
226226 def handle_event (self , event_data : Dict[str , Any]) -> None :
227227 """ Process specific events with proper error handling."""
228228 try :
229229 entity_id = event_data.get(" entity_id" )
230230 if not entity_id:
231231 return
232-
232+
233233 # Process event logic here
234234 self ._process_event_logic(entity_id, event_data)
235-
235+
236236 except Exception as e:
237237 print (f " Error handling event in { self .__class__ .__name__ } : { e} " )
238-
238+
239239 async def update (self , current_tick : int ) -> None :
240240 """ Main system update loop called each simulation tick."""
241241 # Periodic processing logic here
242242 entities = self .simulation_state.get_entities_with_components([
243243 RequiredComponent
244244 ])
245-
245+
246246 for entity_id, components in entities.items():
247247 await self ._process_entity(entity_id, components, current_tick)
248-
248+
249249 def _process_entity (self , entity_id : str , components : Dict, tick : int ):
250250 """ Process individual entity - separate method for testing."""
251251 pass
@@ -268,12 +268,12 @@ class AgentConfig(BaseModel):
268268 max_health: int = Field(default = 100 , gt = 0 , description = " Maximum health points" )
269269 learning_rate: float = Field(default = 0.01 , gt = 0 , le = 1 , description = " Learning rate for Q-learning" )
270270 memory_capacity: int = Field(default = 1000 , gt = 0 , description = " Size of agent memory buffer" )
271-
271+
272272class EnvironmentConfig (BaseModel ):
273273 """ Configuration for world environment settings."""
274274 grid_size: tuple[int , int ] = Field(default = (50 , 50 ), description = " World dimensions" )
275275 resource_spawn_rate: float = Field(default = 0.02 , ge = 0 , le = 1 , description = " Resource spawn probability per tick" )
276-
276+
277277class SimulationConfig (BaseModel ):
278278 """ Top-level simulation configuration."""
279279 agent: AgentConfig = Field(default_factory = AgentConfig)
@@ -328,7 +328,7 @@ class GoodComponent(Component):
328328 self .max_health = max_health
329329 self .current_health = max_health # Just data storage
330330 self .damage_taken = 0
331-
331+
332332 # Properties for computed values are acceptable
333333 @ property
334334 def is_alive (self ) -> bool :
@@ -366,7 +366,7 @@ for entity_id, components in entities.items():
366366``` python
367367class OptimizedComponent (Component ):
368368 __slots__ = [' x' , ' y' , ' timestamp' ] # Reduces memory overhead
369-
369+
370370 def __init__ (self , x : int , y : int ):
371371 self .x = x
372372 self .y = y
@@ -383,10 +383,10 @@ class OptimizedComponent(Component):
383383# Efficient event handling
384384def __init__ (self , simulation_state , config , cognitive_scaffold ):
385385 super ().__init__ (simulation_state, config, cognitive_scaffold)
386-
386+
387387 # Subscribe to specific, relevant events only
388388 if self .event_bus:
389389 self .event_bus.subscribe(" agent_death" , self .handle_death)
390390 self .event_bus.subscribe(" resource_depleted" , self .handle_depletion)
391391 # Avoid subscribing to "all_events" or overly broad categories
392- ```
392+ ```
0 commit comments