46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
|
|
from abc import ABC, abstractmethod
|
||
|
|
|
||
|
|
|
||
|
|
class Behavior(ABC):
|
||
|
|
"""
|
||
|
|
Base interface for skills.
|
||
|
|
Each skill must implement:
|
||
|
|
- execute(reset: bool, *args) -> bool
|
||
|
|
- is_ready(*args) -> bool
|
||
|
|
"""
|
||
|
|
|
||
|
|
def __init__(self, agent):
|
||
|
|
from agent.base_agent import Base_Agent # type hinting
|
||
|
|
|
||
|
|
self.agent: Base_Agent = agent
|
||
|
|
|
||
|
|
@abstractmethod
|
||
|
|
def execute(self, reset: bool, *args, **kwargs) -> bool:
|
||
|
|
"""
|
||
|
|
Executes one step of the skill.
|
||
|
|
|
||
|
|
Parameters
|
||
|
|
----------
|
||
|
|
reset : bool
|
||
|
|
Indicates if this is the first invocation of this skill (should reset internal state).
|
||
|
|
*args
|
||
|
|
Skill-specific arguments.
|
||
|
|
|
||
|
|
Returns
|
||
|
|
-------
|
||
|
|
finished : bool
|
||
|
|
True if the skill has finished execution.
|
||
|
|
"""
|
||
|
|
raise NotImplementedError("Method 'execute' must be implemented in the Skill.")
|
||
|
|
|
||
|
|
@abstractmethod
|
||
|
|
def is_ready(self, *args) -> bool:
|
||
|
|
"""
|
||
|
|
Checks if the current conditions allow starting the skill.
|
||
|
|
|
||
|
|
Returns
|
||
|
|
-------
|
||
|
|
ready : bool
|
||
|
|
"""
|
||
|
|
raise NotImplementedError("Method 'is_ready' must be implemented in the Skill.")
|