@@ -83,6 +83,20 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
8383 self ._steps : int = 0
8484 self ._time : TimeT = 0 # the model's clock
8585
86+ # Wrap the user-defined step method
87+ if hasattr (self , "step" ):
88+ self ._user_step = self .step
89+ self .step = self ._wrapped_step
90+
91+ def _wrapped_step (self , * args : Any , ** kwargs : Any ) -> None :
92+ """Automatically increments time and steps after calling the user's step method."""
93+ # Automatically increment time and step counters
94+ self ._time += kwargs .get ("time" , 1 )
95+ self ._steps += kwargs .get ("step" , 1 )
96+ # Call the original user-defined step method
97+ if self ._user_step :
98+ self ._user_step (* args , ** kwargs )
99+
86100 @property
87101 def agents (self ) -> AgentSet :
88102 """Provides an AgentSet of all agents in the model, combining agents from all types."""
@@ -180,11 +194,6 @@ def run_model(self) -> None:
180194 def step (self ) -> None :
181195 """A single step. Fill in here."""
182196
183- def _advance_time (self , deltat : TimeT = 1 ):
184- """Increment the model's steps counter and clock."""
185- self ._steps += 1
186- self ._time += deltat
187-
188197 def next_id (self ) -> int :
189198 """Return the next unique ID for agents, increment current_id"""
190199 self .current_id += 1
0 commit comments