Skip to content

Commit

Permalink
fix(botix): adapt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Whth committed May 28, 2024
1 parent befbef1 commit f3efbe0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
20 changes: 13 additions & 7 deletions src/mentabotix/modules/botix.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ def rand_move(
indexes = tuple(range(len(speeds)))

# Register a context updater to update the turn direction before entering the behavior.
_updater = con.register_context_updater(
_updater = con.register_context_executor(
make_weighted_selector(speeds, weights) if weights else lambda: speeds[choice(indexes)],
output_keys=[used_ctx_varname],
input_keys=[],
function_name=f"update_{used_ctx_varname}",
)

# Configure speed expressions and actions before entering, implementing random turning.
Expand Down Expand Up @@ -439,10 +439,10 @@ def rand_spd_straight(
if weights and len(weights) != len(speeds):
raise ValueError(f"weights and speeds must have the same length, got speeds: {speeds}, weights: {weights}.")
# Register a context updater to update the turn direction before entering this behavior.
_updater = con.register_context_updater(
_updater = con.register_context_executor(
make_weighted_selector(speeds, weights) if weights else lambda: choice(speeds),
output_keys=[used_ctx_varname],
input_keys=[],
function_name=f"update_{used_ctx_varname}",
)

# Set speed expressions and actions before entering, implementing random turning.
Expand Down Expand Up @@ -545,7 +545,9 @@ def _dir() -> int:
return 1 if random() < turn_left_prob else -1

# Register a context updater to update the turn direction before entering this behavior.
_updater = con.register_context_updater(_dir, output_keys=[used_ctx_varname], input_keys=[])
_updater = con.register_context_executor(
_dir, output_keys=[used_ctx_varname], function_name=f"update_{used_ctx_varname}"
)

# Set speed expressions and actions before entering, implementing random turning.
return cls(
Expand Down Expand Up @@ -594,7 +596,9 @@ def rand_spd_turn(

# Register a context updater to update the turn direction before entering this behavior.

_updater = con.register_context_updater(_spd, output_keys=[used_ctx_varname], input_keys=[])
_updater = con.register_context_executor(
_spd, output_keys=[used_ctx_varname], function_name=f"update_{used_ctx_varname}"
)

# Set speed expressions and actions before entering, implementing random turning.

Expand Down Expand Up @@ -633,7 +637,9 @@ def rand_dir_spd_turn(
_spd = make_weighted_selector(turn_speeds, weights) if weights else lambda: choice(turn_speeds)

# Register a context updater to update the turn direction before entering this behavior.
_updater = con.register_context_updater(_spd, output_keys=[used_ctx_varname], input_keys=[])
_updater = con.register_context_executor(
_spd, output_keys=[used_ctx_varname], function_name=f"update_{used_ctx_varname}"
)

# Set speed expressions and actions before entering, implementing random turning.
return cls(
Expand Down
20 changes: 0 additions & 20 deletions src/mentabotix/tools/composers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,6 @@ def _add_with_connection_check(self, unit: MovingState | MovingTransition) -> Se
self._flip()
return self

def _mid_transition_inject(self, states, transitions):
for sta, tran in zip(states, transitions):
# Ensure each state is in the corresponding transition's to_states
if sta not in tran.to_states.values():
raise ValueError(f"The state {sta} should be in the to_states of the transition {tran}!")
if self.last_state and self.last_state not in tran.from_states:
raise ValueError(f"The state {self.last_state} should be in the from_states of the transition {tran}!")
self._chain_container[MovingState].append(sta)
self._chain_container[MovingTransition].append(tran)

def _mid_state_inject(self, states, transitions):
for sta, tran in zip(states, transitions):
# Ensure each state is in the corresponding transition's from_states
if sta not in tran.from_states:
raise ValueError(f"The state {sta} should be in the from_states of the transition {tran}!")
if sta not in self.last_transition.to_states.values():
raise ValueError(f"The state {sta} should be in the to_states of the transition {tran}!")
self._chain_container[MovingState].append(sta)
self._chain_container[MovingTransition].append(tran)


KT = TypeVar("KT", bound=Hashable)

Expand Down

0 comments on commit f3efbe0

Please sign in to comment.