package AXJava;
import LivinGrimoire.Algorithm;
import java.util.ArrayList;
import java.util.Random;
// (*)Algorithm Dispensers
public class AlgDispenser {
// super class to output an algorithm out of a selection of algorithms
private ArrayList<Algorithm> algs = new ArrayList<Algorithm>();
private int activeAlg = 0;
private Random rand = new Random();
public AlgDispenser(Algorithm...algorithms) {
for (Algorithm alg : algorithms)
{
algs.add(alg);
}
}
public AlgDispenser addAlgorithm(Algorithm alg){
// builder pattern
algs.add(alg);
return this;
}
public Algorithm dispenseAlgorithm(){
return algs.get(activeAlg);
}
public Algorithm rndAld(){
// return a random algorithm
return algs.get(rand.nextInt(algs.size()));
}
public void moodAlg(int mood){
// set output algorithm based on number representing mood
if ((mood>-1) && mood < (algs.size())){
activeAlg = mood;
}
}
public void algUpdate(int mood,Algorithm alg){
// update an algorithm
if (!((mood>-1) && mood < (algs.size()))){
return;
}
algs.set(mood,alg);
}
public void algRemove(int mood){
// remove an algorithm
if (!((mood>-1) && mood < (algs.size()))){
return;
}
algs.remove(mood);
}
public void cycleAlg(){
activeAlg++;
if (activeAlg == algs.size()){
activeAlg = 0;
}
}
}
package AXJava;
import LivinGrimoire.Algorithm;
import LivinGrimoire.DISkillUtils;
public class AXFriend {
private String myName = "chi"; // default name
private String friend_name = "null";
private Boolean needsFriend = true;
private DISkillUtils diSkillUtils = new DISkillUtils();
private TrgTolerance active = new TrgTolerance(10);
private Boolean friendIsActive = false;
public AXFriend(int tolerance) {
// recommended 11
active = new TrgTolerance(tolerance);
}
public String getMyName() {
return myName;
}
public void setMyName(String myName) {
// make changeable on 1st day
this.myName = myName;
}
public void reset(){
// should reset once a month
friend_name = "null";
needsFriend = true;
active.disable();
friendIsActive = false;
}
public String getFriend_name() {
return friend_name;
}
public Algorithm friendHandShake() {
// engage after reset() or at certain time of day if needsFriend, with snooze
return diSkillUtils.simpleVerbatimAlgorithm("friend_request", "i am " + myName);
}
public Boolean getFriendIsActive() {
return friendIsActive;
}
public Algorithm handle(String ear, String skin, String eye) {
if(needsFriend && ear.contains("i am ")){
// register new friend
active.reset();
friendIsActive = active.trigger();
friend_name = ear.replace("i am ", "");
needsFriend = false;
return friendHandShake();
}
if(ear.contains(myName)){active.reset();}
friendIsActive = active.trigger();
return null;
}
}
from __future__ import annotations
from LivinGrimoireCoreV2 import *
import random
class AlgDispenser:
# super class to output an algorithm out of a selection of algorithms
def __init__(self, *algorithms: Algorithm):
super().__init__()
self._algs: list[Algorithm] = []
self._activeAlg: int = 0
for i in range(0, len(algorithms)):
self._algs.append(algorithms[i])
def addAlgorithm(self, alg: Algorithm) -> AlgDispenser:
# builder pattern
self._algs.append(alg)
return self
def dispenseAlgorithm(self) -> Algorithm:
return self._algs[self._activeAlg]
def rndAlg(self) -> Algorithm:
# return a random algorithm
return self._algs[random.randint(0, len(self._algs))]
def moodAlg(self, mood: int) -> Algorithm:
# set output algorithm based on number representing mood
if len(self._algs) > mood > -1:
self._activeAlg = mood
def algUpdate(self, mood: int, alg: Algorithm):
# update an algorithm
if not (len(self._algs) > mood > -1):
return
self._algs[mood] = alg
def algRemove(self, mood: int):
# remove an algorithm
if not (len(self._algs) > mood > -1):
return
self._algs.pop(mood)
def cycleAlg(self):
self._activeAlg += 1
if self._activeAlg == len(self._algs):
self._activeAlg += 0
class TrGEV3:
# advanced boolean gates with internal logic
# these ease connecting common logic patterns, as triggers
def reset(self):
pass
def input(self, ear: str, skin: str, eye: str):
pass
def trigger(self) -> bool:
return False
class TrgTolerance(TrGEV3):
# this boolean gate will return true till depletion or reset()
def __init__(self, maxrepeats: int):
self._maxrepeats: int = maxrepeats
self._repeates: int = maxrepeats
def reset(self):
# refill trigger
self._repeates = self._maxrepeats
def trigger(self) -> bool:
# will return true till depletion or reset()
if self._repeates > 0:
self._repeates -= 1
return True
return False
def disable(self):
self._repeates = 0
class AXFriend:
def __init__(self, tolerance: int):
# recommended 11
self._active = TrgTolerance(tolerance)
self.myName: str = "chi"
self._friendName: str = "null"
self._needFriend: bool = True
self.diSkillUtil: DISkillUtils = DISkillUtils()
self._friendIsActive: bool = False
def reset(self):
# should reset once a month
self.myName = "null"
self._needFriend = True
self._active.disable()
self._friendIsActive = False
def getFriendName(self):
return self._friendName
def friendHandShake(self) ->Algorithm:
# engage after reset() or at certain time of day if needsFriend, with snooze
return self.diSkillUtil.simpleVerbatimAlgorithm("friend_request", "i am" + self.myName)
def getFriendIsActive(self):
return self._friendIsActive
def handle(self, ear: str, skin: str, eye: str)->Algorithm:
if self._needFriend and ear.__contains__("i am "):
# register new friend
self._active.reset()
self._friendIsActive = self._active.trigger()
self._friendName = ear.replace("i am ", "")
self._needFriend = False
return self.friendHandShake()
if ear.__contains__(self.myName):
self._active.reset()
self._friendIsActive = self._active.trigger()
return None
package AXJava;
public class AXLearnability {
private Boolean algSent = false;
// problems that may result because of the last deployed algorithm:
public UniqueItemSizeLimitedPriorityQueue defcons = new UniqueItemSizeLimitedPriorityQueue();// default size = 5
// major chaotic problems that may result because of the last deployed algorithm:
public UniqueItemSizeLimitedPriorityQueue defcon5 = new UniqueItemSizeLimitedPriorityQueue();
// goals the last deployed algorithm aims to achieve:
public UniqueItemSizeLimitedPriorityQueue goals = new UniqueItemSizeLimitedPriorityQueue();
// how many failures / problems till the algorithm needs to mutate (change)
public TrgTolerance trgTolerance;
public AXLearnability(int tolerance) {
this.trgTolerance = new TrgTolerance(tolerance);
}
public void pendAlg(){
// an algorithm has been deployed
// call this method when an algorithm is deployed (in a DiSkillV2 object)
algSent = true;
trgTolerance.trigger();
}
public void pendAlgWithoutConfirmation(){
// an algorithm has been deployed
algSent = true;
//no need to await for a thank you or check for goal manifestation :
// trgTolerance.trigger();
// using this method instead of the default "pendAlg" is the same as
// giving importance to the stick and not the carrot when learning
// this method is mosly fitting work place situations
}
public Boolean mutateAlg(String input){
// recommendation to mutate the algorithm ? true/ false
if (!algSent) {return false;} // no alg sent=> no reason to mutate
if (goals.contains(input)){trgTolerance.reset();algSent = false;return false;}
// goal manifested the sent algorithm is good => no need to mutate the alg
if (defcon5.contains(input)) {trgTolerance.reset();algSent = false; return true;}
// ^ something bad happend probably because of the sent alg
// recommend alg mutation
if (defcons.contains(input)){algSent = false;return trgTolerance.trigger();}
// ^ negative result, mutate the alg if this occures too much
return false;
}
}
''' PRIORITYQUEUE CLASS '''
# A simple implementation of Priority Queue
# using Queue.
class PriorityQueue(object):
def __init__(self):
self.queue = []
def __str__(self):
return ' '.join([str(i) for i in self.queue])
# for checking if the queue is empty
def isEmpty(self):
return len(self.queue) == 0
# for inserting an element in the queue
def insert(self, data):
self.queue.append(data)
# for popping an element based on Priority
def poll(self) -> object:
if not len(self.queue) == 0:
result0 = self.queue[0]
del self.queue[0]
return result0
return None
''' PRIORITYQUEUE CLASS '''
# A simple implementation of Priority Queue
# using Queue.
class LGFIFO:
def __init__(self):
self.queue = []
def __str__(self):
return ' '.join([str(i) for i in self.queue])
# for checking if the queue is empty
def isEmpty(self):
return len(self.queue) == 0
def peak(self):
if self.isEmpty():
return None
return self.queue[0]
# for inserting an element in the queue
def insert(self, data):
self.queue.append(data)
# for popping an element based on Priority
def poll(self) -> object:
if not len(self.queue) == 0:
result0 = self.queue[0]
del self.queue[0]
return result0
return None
def size(self) -> int:
return len(self.queue)
def clear(self):
self.queue.clear()
def removeItem(self, item):
self.queue.remove(item)
def getRNDElement(self):
if self.isEmpty():
return None
else:
return self.queue[random.randint(0, len(self.queue) -1)]