👨‍💻 dev AXPython pt2

development

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class Map {
    private Hashtable<String,String> pointDescription = new Hashtable<>();
    private Hashtable<String,String> descriptionPoint = new Hashtable<>();
    private LGPointInt currentPosition = new LGPointInt();
    private RegexUtil regexUtil = new RegexUtil();
    public void reset(){
        // sleep location is considered (0,0) location
        currentPosition.reset();
    }
    public void moveBy(int x, int y){
        // shift current position
        currentPosition.moveBy(x,y);
    }
    public void moveTo(String location){
        // use this when the AI is returning home
        if(descriptionPoint.contains(location)){
            String value = descriptionPoint.get(location);
            Point p1 = regexUtil.pointRegex(value);
            LGPointInt temp = new LGPointInt(p1);
            currentPosition.x = temp.x;
            currentPosition.y = temp.y;
        }
    }
    public void write(String description){
        // location name or item description will be
        // saved on the map on the current point position
        String pointStr = currentPosition.toString();
        pointDescription.put(pointStr, description);
        descriptionPoint.put(description,pointStr);
    }
    public String read(){
        // read place description
        return pointDescription.getOrDefault(currentPosition.toString(),"null");
    }
    public String read(LGPointInt p1){
        // used for predition of upcoming locations
        return pointDescription.getOrDefault(p1.toString(),"null");
    }
    public String read(String description){
        // get location coordinate
        return descriptionPoint.getOrDefault(description, "null");
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class Map:
    def __init__(self):
        self._pointDescription: dict[str, str] = {}
        self._descriptionPoint: dict[str, str] = {}
        self._currentPosition: LGPointInt = LGPointInt(0, 0)
        self.regexUtil: RegexUtil = RegexUtil()

    def reset(self):
        # sleep location is considered (0,0) location
        self._currentPosition.reset()

    def moveBy(self, x: int, y: int):
        # shift current position
        self._currentPosition.shift(x, y)

    def moveTo(self, location: str):
        # use this when the AI is returning home
        if self._descriptionPoint.__contains__(location):
            value: str = self._descriptionPoint[location]
            p1 = self.regexUtil.pointRegex(value)
            self._currentPosition.x = p1.x
            self._currentPosition.y = p1.y

    def write(self, description):
        # location name or item description will be
        # saved on the map on the current point position
        pointStr: str = self._currentPosition.__repr__()
        self._pointDescription[pointStr] = description
        self._descriptionPoint[description] = pointStr

    def read(self) -> str:
        # read place description
        temp:str = self._currentPosition.__repr__()
        if not self._pointDescription.__contains__(temp):
            return "null"
        return self._pointDescription[temp]

    def readPoint(self, p1: LGPointInt) -> str:
        # used for predition of upcoming locations
        # returns: what is the location name at point
        temp: str = p1.__repr__()
        if not self._pointDescription.__contains__(temp):
            return "null"
        return self._pointDescription[temp]

    def locationCoordinate(self, description):
        # get location coordinate
        if not self._descriptionPoint.__contains__(description):
            return "null"
        return self._descriptionPoint[description]
 
Last edited:

owly

闇の伝説
Staff member
戦闘 コーダー
UniqueItemSizeLimitedPriorityQueue seems to mug RepeatedElements so we don't need the later
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class SkillHubAlgDispenser {
//     super class to output an algorithm out of a selection of skills
//      engage the hub with dispenseAlg and return the value to outAlg attribute
//      of the containing skill (which houses the skill hub)
//      this module enables using a selection of 1 skill for triggers instead of having the triggers engage on multible skill
//       the methode is ideal for learnability and behavioral modifications
//       use a learnability auxiliary module as a condition to run an active skill shuffle or change methode
//       (rndAlg , cycleAlg)
//       moods can be used for specific cases to change behavior of the AGI, for example low energy state
//       for that use (moodAlg)
    private ArrayList<DiSkillV2> skills = new ArrayList<DiSkillV2>();
    private int activeSkill = 0;
    private Neuron tempN = new Neuron();;
    private Random rand = new Random();
    public SkillHubAlgDispenser(DiSkillV2...skillsParams) {
        for (DiSkillV2 skill : skillsParams)
        {
            skills.add(skill);
        }
    }
    public SkillHubAlgDispenser addSkill(DiSkillV2 skill){
        // builder pattern
        skills.add(skill);
        return this;
    }
    public Algorithm dispenseAlgorithm(String ear, String skin, String eye){
        // return value to outAlg param of (external) summoner DiskillV2
        skills.get(activeSkill).input(ear,skin,eye);
        tempN.empty();
        skills.get(activeSkill).output(tempN);
        if (!tempN.negativeAlgParts.isEmpty()){
            return tempN.negativeAlgParts.get(0);
        }
        if (!tempN.algParts.isEmpty()){
            return tempN.algParts.get(0);
        }
        return null;
    }
    public void randomizeActiveSkill(){
        activeSkill = rand.nextInt(skills.size());
    }
    public void setActiveSkillWithMood(int mood){
        // mood integer represents active skill
        // different mood = different behavior
        if ((mood>-1) && mood < (skills.size())){
            activeSkill = mood;
        }
    }
    public void cycleActiveSkill(){
        // changes active skill
        // I recommend this method be triggered with a Learnability or SpiderSense object
        activeSkill++;
        if (activeSkill == skills.size()){
            activeSkill = 0;
        }
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class SkillHubAlgDispenser:
    """super class to output an algorithm out of a selection of skills
//      engage the hub with dispenseAlg and return the value to outAlg attribute
//      of the containing skill (which houses the skill hub)
//      this module enables using a selection of 1 skill for triggers instead of having the triggers engage on multible skill
//       the methode is ideal for learnability and behavioral modifications
//       use a learnability auxiliary module as a condition to run an active skill shuffle or change methode
//       (rndAlg , cycleAlg)
//       moods can be used for specific cases to change behavior of the AGI, for example low energy state
//       for that use (moodAlg)"""

    def __init__(self, *skillsParams: DiSkillV2):
        super().__init__()
        self._skills: list[DiSkillV2] = []
        self._activeSkill: int = 0
        self._tempN: Neuron = Neuron()
        for i in range(0, len(skillsParams)):
            self._skills.append(skillsParams[i])

    def addSkill(self, skill: DiSkillV2) -> SkillHubAlgDispenser:
        # builder pattern
        self._skills.append(skill)
        return self

    def dispenseAlgorithm(self, ear: str, skin: str, eye: str) -> Algorithm:
        # return value to outAlg param of (external) summoner DiskillV2
        self._skills[self._activeSkill].input(ear, skin, eye)
        self._tempN.empty()
        self._skills[self._activeSkill].output(self._tempN)
        if not self._tempN.negativeAlgParts:
            return self._tempN.negativeAlgParts[0]
        if not self._tempN.algParts:
            return self._tempN.algParts[0]
        return None

    def randomizeActiveSkill(self):
        self._activeSkill = random.randint(0, len(self._skills) - 1)

    def setActiveSkillWithMood(self, mood: int):
        # mood integer represents active skill
        # different mood = different behavior
        if -1 < mood < len(self._skills) - 1:
            self._activeSkill = mood

    def cycleActiveSkill(self):
        # changes active skill
        # I recommend this method be triggered with a Learnability or SpiderSense object
        self._activeSkill += 1
        if self._activeSkill == len(self._skills):
            self._activeSkill = 0
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class Catche {
    private Hashtable<String,String> dic1 = new Hashtable<>();
    private int limit = 3;

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getLimit() {
        return limit;
    }

    public Boolean containsKey(String str1){
        return dic1.containsKey(str1);
    }
    public void overwriteInsert(String oldKey,String key, String value){
        int index = dicIndex.get(oldKey);
        dicIndex.put(key,index);
        dicIndex.remove(oldKey);
        indexDic.remove(index);
        indexDic.put(index,key);
        dic1.remove(oldKey);
        dic1.put(key,value);
    }
    public Boolean hasRoom(){
        return limit > dic1.size();
    }
    private Hashtable<Integer,String> indexDic = new Hashtable<>();
    private Hashtable<String, Integer> dicIndex = new Hashtable<>();
    public void Insert(String key, String value){
        if (hasRoom()) {
            int index = dic1.size();
            dic1.put(key,value);
            indexDic.put(index,key);
            dicIndex.put(key,index);
        }
    }
    public void insertAt(int position, String key, String value){
        if (!(position < limit) || !(position > -1)){
            return;
        }
        String oldkey = indexDic.get(position);
        dic1.remove(oldkey);
        dic1.put(key,value);
        indexDic.put(position, key);
        dicIndex.remove(oldkey);
        dicIndex.put(key,position);
    }
    public String getItem(String key){
        return dic1.getOrDefault(key,"");
    }
    public String getItem(int position){
        if (!(position < limit) || !(position > -1)){
            return "";
        }
        String key = indexDic.get(position);
        return dic1.getOrDefault(key,"");
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class Catche:
    # limited sized dictionary
    def __init__(self, size):
        super().__init__()
        self._limit: int = size
        self._keys: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(size)
        self._d1: dict[str, str] = {}

    def insert(self, key: str, value: str):
        # update
        if self._d1.__contains__(key):
            self._d1[key] = value
            return
        # insert:
        if self._keys.size() == self._limit:
            temp = self._keys.peak()
            del self._d1[temp]
        self._keys.insert(key)
        self._d1[key] = value

    def clear(self):
        self._keys.clear()
        self._d1.clear()

    def read(self, key: str) -> str:
        if not self._d1.__contains__(key):
            return "null"
        return self._d1[key]
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class SpiderSense {
    // enables event prediction
    private Boolean spiderSense = false;
    private UniqueItemSizeLimitedPriorityQueue events = new UniqueItemSizeLimitedPriorityQueue();
    private UniqueItemSizeLimitedPriorityQueue alerts = new UniqueItemSizeLimitedPriorityQueue();
    private String prev = "";
    public SpiderSense addEvent(String event){
        // builder pattern
        events.add(event);
        return this;
    }
    // input param  can be run through an input filter prior to this function
    // weather related data (sky state) only for example for weather events predictions
    public void learn(String in1){
        // simple prediction of an event from the events que :
        if (alerts.contains(in1)){
            spiderSense = true;return;
        }
        // event has occured, remember what lead to it
        if (events.contains(in1)){
            alerts.add(prev);return;
        }
        // nothing happend
        prev = in1;
    }

    public Boolean getSpiderSense() {
        // spider sense is tingling? event predicted?
        Boolean temp = spiderSense; spiderSense = false;
        return temp;
    }
    public ArrayList<String> getAlertsShallowCopy(){
        // return shallow copy of alerts list
        return alerts.getElements();
    }
    public ArrayList<String> getAlertsClone(){
        // return deep copy of alerts list
        DeepCopier dc = new DeepCopier();
        return dc.copyList(alerts.getElements());
    }
    public void clearAlerts(){
        // this can for example prevent war, because say once a month or a year you stop
        // being on alert against a rival
        alerts.clear();
    }
    // side note:
    // use separate spider sense for data learned by hear say in contrast to actual experience
    // as well as lies (false predictions)
}
 

fukurou

the supreme coder
ADMIN
Python:
class SpiderSense:
    # enables event prediction
    def __init__(self, lim: int):
        super().__init__()
        self._spiderSense: bool = False
        self._events: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(lim)
        self._alerts: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(lim)
        self._prev: str = ""

    def addEvent(self, event: str):
        # builder pattern
        self._events.insert(event)
        return self

    """input param  can be run through an input filter prior to this function
     weather related data (sky state) only for example for weather events predictions"""

    """side note:
     use separate spider sense for data learned by hear say in contrast to actual experience
     as well as lies (false predictions)"""

    def learn(self, in1: str):
        # simple prediction of an event from the events que :
        if self._alerts.contains(in1):
            self._spiderSense = True
            return
        # event has occured, remember what lead to it
        if self._events.contains(in1):
            self._alerts.insert(self._prev)
            return
        # nothing happend
        self._prev = in1

    def getSpiderSense(self) -> bool:
        # spider sense is tingling? event predicted?
        temp: bool = self._spiderSense
        self._spiderSense = False
        return temp

    def getAlertsShallowCopy(self):
        # return shallow copy of alerts list
        return self._alerts.queue

    def getAlertsClone(self) -> list[str]:
        # return deep copy of alerts list
        l_temp: list[str] = []
        for item in self._alerts.queue:
            l_temp.append(item)
        return l_temp

    def clearAlerts(self):
        """this can for example prevent war, because say once a month or a year you stop
         being on alert against a rival"""
        self._alerts.clear()
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class TrgMinute extends TrGEV3{
    // trigger true at minute once per hour
    private int hour1 = -1;
    int minute;
    private Random rand = new Random();
    private PlayGround pl = new PlayGround();
    public TrgMinute() {
        minute = rand.nextInt(60);
    }

    public TrgMinute(int minute) {
        this.minute = minute;
    }

    @Override
    public Boolean trigger() {
        int tempHour = pl.getHoursAsInt();
        if(tempHour!=hour1){
            if(pl.getMinutesAsInt() == minute){
                hour1 = tempHour;
                return true;
            }
        }
        return false;
    }

    @Override
    public void reset() {
        hour1 = -1;
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class TrgMinute(TrGEV3):
    # trigger true at minute once per hour
    def __init__(self):
        super().__init__()
        self._hour1: int = -1
        self._minute: int = random.randint(0, 60)
        self.pgrd: PlayGround = PlayGround()

    def setMinute(self, minute):
        if -1 < minute < 61:
            self._minute = minute

    # override
    def trigger(self) -> bool:
        temp_hour: int = self.pgrd.getHoursAsInt()
        if temp_hour != self._hour1:
            if self.pgrd.getMinutesAsInt() == self._minute:
                self._hour1 = temp_hour
                return True
        return False

    # override
    def reset(self):
        self._hour1 = -1
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class TrgParrot {
    // simulates a parrot chirp trigger mechanism
    // as such this trigger is off at night
    // in essence this trigger says: I am here, are you here? good.
    private TrgTolerance tolerance = new TrgTolerance(3);
    private Responder silencer = new Responder("ok","okay","stop","shut up","quiet");
    private PlayGround pl = new PlayGround();

    public void setTolerance(int limit) {
        if(limit>0){
        this.tolerance = new TrgTolerance(limit);}
    }

    public Boolean trigger(Boolean standBy, String ear){
        // relies on the Kokoro standby boolean
        // no input or output for a set amount of time results with a true
        // and replenishing the trigger.
        if(pl.isNight()){
            // is it night? I will be quite
            return false;
        }
        // you want the bird to shut up?
        if(silencer.responsesContainsStr(ear)){
            tolerance.disable();
            return false;
        }
        // no input or output for a while?
        if(standBy){
            // I will chirp
            tolerance.reset();;
            return true;
        }
        // we are handshaking?
        if(!ear.isEmpty()){
            // I will reply chirp till it grows old for me (a set amount of times till reset)
            if(tolerance.trigger()){
                return true;
            }
        }
        return false;
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class TrgParrot:
    # simulates a parrot chirp trigger mechanism
    # as such this trigger is off at night
    # in essence this trigger says: I am here, are you here? good.
    def __init__(self, limit: int):
        super().__init__()
        temp_lim: int = 3
        if limit > 0:
            temp_lim = limit
        self._tolerance: TrgTolerance = TrgTolerance(temp_lim)
        self._silencer: Responder = Responder("ok", "okay", "stop", "shut up", "quiet")
        self._pl: PlayGround = PlayGround()

    def trigger(self, standBy: bool, ear: str) -> bool:
        """relies on the Kokoro standby boolean
         no input or output for a set amount of time results with a true
         and replenishing the trigger."""
        if self._pl.isNight():
            # is it night? I will be quite
            return False
        # you want the bird to shut up?
        if self._silencer.responsesContainsStr(ear):
            self._tolerance.disable()
            return False
        # no input or output for a while?
        if standBy:
            # I will chirp!
            self._tolerance.reset()
            return True
        # we are handshaking?
        if not ear == "":
            # I will reply chirp till it grows old for me (a set amount of times till reset)
            if self._tolerance.trigger():
                return True
        return False
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class TrgSnooze extends TrGEV3{
    // this boolean gate will return true per minute interval
    // max repeats times.
    private int repeats = 0;
    private int maxrepeats; //2 recomended
    private Boolean snooze = true;
    private int snoozeInterval = 5;
    private PlayGround playGround = new PlayGround();
    public TrgSnooze(int maxrepeats) {
        this.maxrepeats = maxrepeats;
    }

    public void setSnoozeInterval(int snoozeInterval) {
        if((snoozeInterval > 1)&&(snoozeInterval<11)){
            this.snoozeInterval = snoozeInterval;
        }
    }
    public void setMaxrepeats(int maxrepeats) {
        this.maxrepeats = maxrepeats;
        reset();
    }
    @Override
    public void reset() {
        // refill trigger
        // engage this code when an alarm clock was engaged to enable snoozing
        repeats = maxrepeats;
    }

    @Override
    public Boolean trigger() {
        // trigger a snooze alarm?
        int minutes = playGround.getMinutesAsInt();
        if(minutes%snoozeInterval !=0){
            snooze = true;
            return false;
        }
        if ((repeats > 0)&&(snooze)) {
            snooze = false;
            repeats--;
            return true;
        }
        return false;
    }
    public void disable(){
        // engage this method to stop the snoozing
        repeats = 0;
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class TrgSnooze(TrGEV3):
    # this boolean gate will return true per minute interval
    # max repeats times.
    def __init__(self, maxRepeats: int):
        super().__init__()
        self._repeats: int = 0
        self._maxRepeats: int = maxRepeats
        self._snooze: bool = True
        self._snoozeInterval: int = 5
        self._playGround: PlayGround = PlayGround()

    def setSnoozeInterval(self, snoozeInterval):
        if 1 < snoozeInterval < 11:
            self._snoozeInterval = snoozeInterval

    # override
    def reset(self):
        # refill trigger
        # engage this code when an alarm clock was engaged to enable snoozing
        self._repeats = self._maxRepeats

    def setMaxrepeats(self, max_repeats: int):
        self._maxRepeats = max_repeats
        self.reset()

    # override
    def trigger(self) -> bool:
        # trigger a snooze alarm?
        minutes: int = self._playGround.getMinutesAsInt()
        # non interval minute case:
        if minutes % self._snoozeInterval != 0:
            self._snooze = True
            return False
        # 1 time activation per snooze interval minute:
        if self._repeats > 0 and self._snooze:
            self._snooze = False
            self._repeats -= 1
            return True
        return False

    def disable(self):
        # engage this method to stop the snoozing
        self._repeats = 0
 
Top