battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionTheShell gives the livingrimoire command prompt like abilities EmptyTheShell gives the livingrimoire command prompt like abilities

more_horiz
The shell is a unique livingrimoire skill. it enables installing and uninstalling skills while the code is running.

main code example use(Java):

Code:

       Sh_Brain b1 = new Sh_Brain();
        b1.setShell(new TheShell(b1));
        // adding all skills:
        b1.addLogicSkill("hello world", new DiHelloWorld());
        b1.addHardwareSkill("output",new DiSysOut()); // this skill prints output
        // ^ shell filled with skills
        b1.doIt("install output", "","");
        b1.doIt("install hello world", "","");
        b1.doIt("hello", "","");
        b1.doIt("abolish hello world", "","");
        b1.doIt("hello", "","");
        System.out.println("skill reinstall:");
        b1.doIt("install hello world", "","");
        b1.doIt("hello", "","");

output:

hardware skill has been installed
logic skill has been installed
hello world
logic skill has been uninstalled
skill reinstall:
logic skill has been installed
hello world

:s32: up till now the coder would hardcode the skills he wants the LivinGrimoire AGI software design patten, then
run the code.

TheShell enables modifying the skills which the livingrimoire is equipped with while the program is running.

so you can simply add all the skills to TheSkill, start running the program and then add/remove skills to the livingrimoire object using key phrases.

much like the install and uninstall commands command shells use to enable more commands.

Last edited by Moti Barski on Wed Oct 18, 2023 11:05 pm; edited 1 time in total

descriptionTheShell gives the livingrimoire command prompt like abilities EmptyRe: TheShell gives the livingrimoire command prompt like abilities

more_horiz
I think it was on a vb.net book where I read about the doIt method as a concept.
a method that just does what's needed, without need to code.

and I made it. a 1 line software design pattern narrowed down to that omni solve method.

and I also often daydream about being able to modify code while it was being run. like
I heard the LISP PL does.

it's about efficiency IG, you run less code lines when you can turn code snippets on and off, rather than check each time on their on off state (using TheShell skill).

descriptionTheShell gives the livingrimoire command prompt like abilities EmptyRe: TheShell gives the livingrimoire command prompt like abilities

more_horiz
TheShell:

Code:

package skills;

import AXJava.AXCmdBreaker;
import LivinGrimoire.Chobits;
import LivinGrimoire.DiSkillV2;

import java.util.Hashtable;

public class TheShell extends DiSkillV2 {
    public Chobits shellChobit = new Chobits();
    protected Chobits logicChobit;
    protected Chobits hardwareChobit;
    protected Hashtable<String,DiSkillV2> logicSkills = new Hashtable<>(); // all logic skills
    protected Hashtable<String,DiSkillV2> hardwareSkills = new Hashtable<>(); // all hardware skills
    protected AXCmdBreaker installer = new AXCmdBreaker("install");
    protected AXCmdBreaker uninstaller = new AXCmdBreaker("abolish");
    protected String temp = "";

    public TheShell(Sh_Brain b1) {
        this.logicChobit = b1.logicChobit;
        this.hardwareChobit = b1.hardwareChobit;
        shellChobit.addSkill(this);
    }

    public void addLogicSkill(String skillName, DiSkillV2 skill){
        logicSkills.put(skillName,skill);
    }
    public void addHardwareSkill(String skillName, DiSkillV2 skill){
        hardwareSkills.put(skillName,skill);
    }
    // shell methods
    private int sh_addSkill(String skillKey){
        if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
            return 0; // skill does not exist
        }
        // find the skill:
        if(logicSkills.containsKey(skillKey)){
            DiSkillV2 ref = logicSkills.get(skillKey);
            if(logicChobit.containsSkill(ref)){
                return 1; // logic skill already installed
            }
            logicChobit.addSkill(ref);
            return 2; // logic skill has been installed
        }
        DiSkillV2 ref = hardwareSkills.get(skillKey);
        if(hardwareChobit.containsSkill(ref)){
            return 3; // hardware skill already installed
        }
        hardwareChobit.addSkill(ref);
        return 4; // hardware skill has been installed
    }
    private int sh_removeSkill(String skillKey){
        if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
            return 0; // skill does not exist
        }
        if(logicSkills.containsKey(skillKey)){
            DiSkillV2 ref = logicSkills.get(skillKey);
            if(logicChobit.containsSkill(ref)){
                logicChobit.removeSkill(ref);
                return 1; // logic skill has been uninstalled
            }
            return 2; // logic skill is not installed
        }
        DiSkillV2 ref = hardwareSkills.get(skillKey);
        if(hardwareChobit.containsSkill(ref)){
            hardwareChobit.removeSkill(ref);
            return 3; // hardware skill has been uninstalled
        }
        return 4; // hardware skill is not installed
    }
    private void sh_removeAllSkills(){logicChobit.clearSkills();hardwareChobit.clearSkills();}
    @Override
    public void input(String ear, String skin, String eye) {
        if (ear.equals("remove all skills")){
            sh_removeAllSkills();
            return;
        }
        temp = installer.extractCmdParam(ear);
        if (!temp.isEmpty()){
            switch (sh_addSkill(temp)){
                case 0:
                    setVerbatimAlg(4, "skill does not exist");
                    break;
                case 1:
                    setVerbatimAlg(4, "logic skill already installed");
                    break;
                case 2:
                    setVerbatimAlg(4, "logic skill has been installed");
                    break;
                case 3:
                    setVerbatimAlg(4, "hardware skill already installed");
                    break;
                case 4:
                    setVerbatimAlg(4, "hardware skill has been installed");
                    break;
            }
            temp = "";
            return;
        }
        temp = uninstaller.extractCmdParam(ear);
        if (!temp.isEmpty()){
            switch (sh_removeSkill(temp)){
                case 0:
                    setVerbatimAlg(4, "skill does not exist");
                    break;
                case 1:
                    setVerbatimAlg(4, "logic skill has been uninstalled");
                    break;
                case 2:
                    setVerbatimAlg(4, "logic skill is not installed");
                    break;
                case 3:
                    setVerbatimAlg(4, "hardware skill has been uninstalled");
                    break;
                case 4:
                    setVerbatimAlg(4, "hardware skill is not installed");
                    break;
            }
            temp = "";
        }
    }
}



Shell Brain class:

Code:

package skills;

import LivinGrimoire.Brain;
import LivinGrimoire.DiSkillV2;

public class Sh_Brain extends Brain {
    private TheShell shell = new TheShell(this);
    private String temp = "";
    public void addLogicSkill(String skillName, DiSkillV2 skill){
        shell.addLogicSkill(skillName, skill);
    }
    public void addHardwareSkill(String skillName, DiSkillV2 skill){
        shell.addHardwareSkill(skillName, skill);
    }

    public void setShell(TheShell shell) {
        // for using TheShell skill subclass objects with different input
        // method logic
        this.shell = shell;
    }

    @Override
    public void doIt(String ear, String skin, String eye) {
        temp = shell.shellChobit.think(ear, skin, eye);
        if(temp.isEmpty()){
            super.doIt(ear, skin, eye);
            return;
        }
        hardwareChobit.think(temp,skin,eye);
    }
}


shell brain is a replacement to the Brain class if you want to use TheShell skill.

Last edited by Moti Barski on Sun Oct 22, 2023 12:49 am; edited 1 time in total

descriptionTheShell gives the livingrimoire command prompt like abilities EmptyRe: TheShell gives the livingrimoire command prompt like abilities

more_horiz
I could have made the skill a stand alone skill, without the need for the Shell brain class,
the thing is this loop inside the chobit class:
for (DiSkillV2 dCls : dClasses) {

it loops through all the skills, so if a skill is added the loop errors because it's size changes while it's(the loop) active.
one solution would be to wrap it in a try catch, but that's not really my style,

plus the chobit would miss the handling of skipped skills when TheSkill is active if you go try catch.

I also want to note that some methods were added to the Chobit class to make TheSkill possible:

removeSkill(skill)
and containsSkill(skill)
which are based on the shallow ref of the skill param. cyberpunk40x40

descriptionTheShell gives the livingrimoire command prompt like abilities EmptyRe: TheShell gives the livingrimoire command prompt like abilities

more_horiz
and here is the python version of the code:

Code:

class TheShell(DiSkillV2):
    def __init__(self, b1: ShBrain):
        super().__init__()
        self.shellChobit: Chobits = Chobits()
        self.logicChobit: Chobits = b1.logicChobit
        self.hardwareChobit: Chobits = b1.hardwareChobit
        self.shellChobit.addSkill(self)
        self.logicSkills: [str, DiSkillV2] = {}
        self.hardwareSkills: [str, DiSkillV2] = {}
        self.installer: AXCmdBreaker = AXCmdBreaker("install")
        self.uninstaller: AXCmdBreaker = AXCmdBreaker("abolish")
        self.temp: str = ""

    def addLogicalSkill(self, skillName: str, skill: DiSkillV2):
        self.logicSkills[skillName] = skill

    def addHardwareSkill(self, skillName: str, skill: DiSkillV2):
        self.hardwareSkills[skillName] = skill

    # shell methods
    def _sh_addSkill(self, skillKey) -> int:
        if not (skillKey in self.logicSkills or skillKey in self.hardwareSkills):
            return 0  # skill does not exist
        # find the skill
        if skillKey in self.logicSkills:
            ref: DiSkillV2 = self.logicSkills[skillKey]
            if self.logicChobit.containsSkill(ref):
                return 1  # logic skill already installed
            self.logicChobit.addSkill(ref)
            return 2  # logic skill has been installed
        ref: DiSkillV2 = self.hardwareSkills[skillKey]
        if self.hardwareChobit.containsSkill(ref):
            return 3  # hardware skill already installed
        self.hardwareChobit.addSkill(ref)
        return 4  # hardware skill has been installed

    def _sh_removeSkill(self, skillKey) -> int:
        if not (skillKey in self.logicSkills or skillKey in self.hardwareSkills):
            return 0  # skill does not exist
        if skillKey in self.logicSkills:
            ref: DiSkillV2 = self.logicSkills[skillKey]
            if self.logicChobit.containsSkill(ref):
                self.logicChobit.removeSkill(ref)
                return 1  # logic skill has been uninstalled
            return 2  # logic skill is not installed
        ref: DiSkillV2 = self.hardwareChobit[skillKey]
        if self.hardwareChobit.containsSkill(ref):
            self.hardwareChobit.removeSkill(ref)
            return 3  # hardware skill has been uninstalled
        return 4  # hardware skill is not installed

    def _sh_removeAllSkills(self):
        self.logicChobit.clearSkills()
        self.hardwareChobit.clearSkills()

    # Override
    def input(self, ear: str, skin: str, eye: str):
        if ear == "remove all skills":
            self._sh_removeAllSkills()
        self.temp = self.installer.extractCmdParam(ear)
        if self.temp:  # string is not empty?
            match (self._sh_addSkill(self.temp)):
                case 0:
                    self.setVerbatimAlg(4, "skill does not exist")
                case 1:
                    self.setVerbatimAlg(4, "logic skill already installed")
                case 2:
                    self.setVerbatimAlg(4, "logic skill has been installed")
                case 3:
                    self.setVerbatimAlg(4, "hardware skill already installed")
                case 4:
                    self.setVerbatimAlg(4, "hardware skill has been installed")
            self.temp = ""
            return
        self.temp = self.uninstaller.extractCmdParam(ear)
        if self.temp:  # string is not empty?
            match (self._sh_removeSkill(self.temp)):
                case 0:
                    self.setVerbatimAlg(4, "skill does not exist")
                case 1:
                    self.setVerbatimAlg(4, "logic skill has been uninstalled")
                case 2:
                    self.setVerbatimAlg(4, "logic skill is not installed")
                case 3:
                    self.setVerbatimAlg(4, "hardware skill has been uninstalled")
                case 4:
                    self.setVerbatimAlg(4, "hardware skill is not installed")
            self.temp = ""


class ShBrain(Brain):
    def __init__(self):
        super().__init__()
        self._shell: TheShell = TheShell(self)
        self._temp: str = ""

    def addLogicalSkill(self, skillName: str, skill: DiSkillV2):
        self._shell.addLogicalSkill(skillName, skill)

    def addHardwareSkill(self, skillName: str, skill: DiSkillV2):
        self._shell.addHardwareSkill(skillName, skill)

    def setShell(self, newShell: TheShell):
        #  for using TheShell skill subclass objects with different input
        #  method logic
        self._shell = newShell

    # Override
    def doIt(self, ear: str, skin: str, eye: str):
        self._temp = self._shell.shellChobit.think(ear, skin, eye)
        if not self._temp:  # is empty?
            super().doIt(ear, skin, eye)
            return
        self.hardwareChobit.think(self._temp, skin, eye)

descriptionTheShell gives the livingrimoire command prompt like abilities EmptyRe: TheShell gives the livingrimoire command prompt like abilities

more_horiz
python TheShell main:

Code:


    b1:ShBrain = ShBrain()
    b1.addLogicalSkill("hello world", DiHelloWorld())
    b1.addHardwareSkill("output", DiSysOut())
    b1.doIt("install output","","")
    b1.doIt("install hello world", "", "")
    b1.doIt("hello", "", "")
    b1.doIt("abolish hello world", "", "")
    b1.doIt("hello", "", "")
    b1.doIt("install hello world", "", "")
    b1.doIt("hello", "", "")
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply