👨‍💻 dev engramic curroputation fix

development

fukurou

the supreme coder
ADMIN
1 add to brain:
Python:
    def exist(self, skill: Skill) -> bool:
        """
        Checks the lobe the skill belongs to (by its skill_lobe attribute),
        in both the regular and continuous lists.
        """
        match skill.get_skill_lobe():
            case 1:
                return self.logicLobe.exist(skill)
            case 2:
                return self.hardwareLobe.exist(skill)
            case 3:
                return self.ear.exist(skill)
            case 4:
                return self.skin.exist(skill)
            case 5:
                return self.eye.exist(skill)
        return False
 

fukurou

the supreme coder
ADMIN
step 2
Python:
class APAddUniqueSkills(AlgPart):
    # adds skills to the brain, skipping any that already exist in any lobe
    def __init__(self, brain: Brain, *skills_to_add: Skill):
        super().__init__()
        self.brain = brain
        self.skills_to_add: list[Skill] = list(skills_to_add)
        self.done = False

    def action(self, ear: str, skin: str, eye: str) -> str:
        for skill in self.skills_to_add:
            if not self.brain.exist(skill):
                self.brain.add_skill(skill)
        self.done = True
        return ""

    def completed(self) -> bool:
        return self.done
 

fukurou

the supreme coder
ADMIN
step 3:

Code:
class AHNagCooldown(Skill):
    """warns when the same input repeats back to back, and if the nagging continues,
    removes the logic lobe's regular skills (except defcon skills, which include
    this one) for a cooldown period, then restores them (without duplicates) and
    resets the repeat counter.
    defcon skills are those whose skillNotes("type") returns "defcon"
    """
    def __init__(self, brain: Brain, cooldown_minutes=3, warn_at=3, hibernate_at=6):
        super().__init__()
        self.brain = brain
        self.tg: TimeGate = TimeGate(cooldown_minutes)
        self.warn_at = max(2, warn_at)  # clamp
        self.hibernate_at = max(self.warn_at + 1, hibernate_at)  # always after the warning
        self.hibernating = False
        self._removed: list[Skill] = []  # skills taken out during the cooldown
        self._last_ear = ""
        self._repeat_count = 0

    def _normalize(self, ear: str) -> str:
        # "Nag!", "nag " and "NAG" all count as the same input
        cleaned = "".join(c for c in ear.lower() if c.isalnum() or c.isspace())
        return " ".join(cleaned.split())

    def _count_repeats(self, ear: str) -> int:
        # consecutive repeats of the same input, empty input is ignored
        if not isinstance(ear, str):
            return self._repeat_count
        text = self._normalize(ear)
        if text == "":
            return self._repeat_count
        if text == self._last_ear:
            self._repeat_count += 1
        else:
            self._last_ear = text
            self._repeat_count = 1
        return self._repeat_count

    def _reset_counter(self):
        self._last_ear = ""
        self._repeat_count = 0

    def input(self, ear: str, skin: str, eye: str):
        if not self.hibernating:
            count = self._count_repeats(ear)
            if count >= self.hibernate_at:
                # ===================== HIBERNATION STARTS HERE =====================
                # snapshot the logic lobe's regular skills, minus defcon skills (incl. me)
                self._removed = [s for s in list(self.brain.logicLobe.dClasses)
                                 if s.skillNotes("type") != "defcon"]
                self.hibernating = True
                self._reset_counter()
                self.tg.openForPauseMinutes()
                # announce first, then remove the skills
                self.algPartsFusion(4,
                                    APVerbatim("I'm hibernating now, talk to you later"),
                                    APSkillsRemover(self.brain, *self._removed))
                # ===================================================================
            elif count == self.warn_at:
                # tier 1: warning, fires once at the threshold, nothing is removed
                self.setSimpleAlg("stop repeating yourself")
        else:
            if self.tg.isClosed():
                # ===================== HIBERNATION ENDS HERE =======================
                self.hibernating = False
                self._reset_counter()  # back to square one
                # clear throat, then put the skills back (skipping ones already present)
                self.algPartsFusion(4,
                                    APVerbatim("ahem"),
                                    APAddUniqueSkills(self.brain, *self._removed))
                self._removed = []
                # ===================================================================

    def skillNotes(self, param: str) -> str:
        if param == "type":
            return "defcon"
        elif param == "notes":
            return "warns on repeated input, then hibernates other skills for a cooldown"
        elif param == "triggers":
            return "repeat the same input back to back"
        return "note unavailable"
 
Last edited:

fukurou

the supreme coder
ADMIN
step 4:
Python:
class AHNight(Skill):
    # this skill swaps between two sets of contradicting skills
    # hidden skills are enabled at night
    # negation skills(if any) are enabled for daytime
    def __init__(self, brain: Brain, *hidden_skills: Skill):
        super().__init__()
        self.hidden_skills: list[Skill] = list(hidden_skills)
        self.brain = brain
        self.engaged: bool = False

    def _load_skills(self, skills: list[Skill]):
        for skill in skills:
            if not self.brain.exist(skill):
                self.brain.add_skill(skill)

    def _remove_skills(self, skills: list[Skill]):
        for skill in skills:
            self.brain.remove_skill(skill)

    def manifest(self):
        if TimeUtils.isNight():
            self._load_skills(self.hidden_skills)
            self.engaged = True
        else:
            self.engaged = False

    def ghost(self):
        if self.engaged:
            self._remove_skills(self.hidden_skills)

    def input(self, ear: str, skin: str, eye: str):
        if TimeUtils.isNight():
            if not self.engaged:
                self.algPartsFusion(3, APAddUniqueSkills(self.brain, *self.hidden_skills))
                self.engaged = True
        elif self.engaged:
            self.algPartsFusion(3, APSkillsRemover(self.brain, *self.hidden_skills))
            self.engaged = False

    def skillNotes(self, param: str) -> str:
        if param == "type":
            return "defcon"
        elif param == "notes":
            return "enables night time behavior"
        elif param == "triggers":
            return f"fully automatic"
        return "note unavailable"


class AHDay(Skill):
    # this skill enables day skills during daytime
    # day skills are removed at nighttime
    def __init__(self, brain: Brain, *day_skills: Skill):
        super().__init__()
        self.day_skills: list[Skill] = list(day_skills)
        self.brain = brain
        self.engaged: bool = False

    def _load_skills(self, skills: list[Skill]):
        for skill in skills:
            if not self.brain.exist(skill):
                self.brain.add_skill(skill)

    def _remove_skills(self, skills: list[Skill]):
        for skill in skills:
            self.brain.remove_skill(skill)

    def manifest(self):
        # load day skills if daytime, mark disengaged if night
        if not TimeUtils.isNight():
            self._load_skills(self.day_skills)
            self.engaged = True
        else:
            self.engaged = False

    def ghost(self):
        # remove day skills if engaged
        if self.engaged:
            self._remove_skills(self.day_skills)

    def input(self, ear: str, skin: str, eye: str):
        if not TimeUtils.isNight():
            # daytime and not yet engaged: add day skills
            if not self.engaged:
                self.algPartsFusion(3, APAddUniqueSkills(self.brain, *self.day_skills))
                self.engaged = True
        elif self.engaged:
            # nighttime and still engaged: remove day skills
            self.algPartsFusion(3, APSkillsRemover(self.brain, *self.day_skills))
            self.engaged = False

    def skillNotes(self, param: str) -> str:
        if param == "type":
            return "defcon"
        elif param == "notes":
            return "enables day time behavior"
        elif param == "triggers":
            return "fully automatic"
        return "note unavailable"
 
Top