class AbsDictionaryDBShadow : AbsDictionaryDB() {
// used as a fill in class if you want to test the chobit and havent built a DB
// class yet
override fun save(key: String, value: String) {}
override fun load(key: String): String {
return "null"
}
}
public interface Mutatable {
public AbsAlgPart mutation();
}
package chobit;
import java.util.ArrayList;
import java.util.Random;
public class APMoan0 extends AbsAlgPart implements Mutatable {
protected Random rand = new Random();
protected final int failed = 3;
protected enumFail failure = enumFail.ok;
protected boolean isComplete = false;
protected ArrayList<String> interactions;
protected ArrayList<String> moans;
protected ArrayList<String> groans;
protected ArrayList<String> moanList;
protected int noInputCounter = 0;
public APMoan0() {
super();
moanList = new ArrayList<>();
moanList.add("1");
moanList.add("2");
interactions = new ArrayList<>();
moans = new ArrayList<>();
groans = new ArrayList<>();
}
@Override
public AbsAlgPart mutation() {
// TODO Auto-generated method stub
return null;
}
@Override
public String action(String ear, String skin, String eye) {
if (!ear.equals("")) {
noInputCounter = 0;
}
if (ear.contains("thank you")) {
isComplete = true;
return "fuck you very much";
}
if (ear.equals("")) {
noInputCounter++;
if (noInputCounter > failed) {
failure = enumFail.fail;
}
} //
else if (interactions.contains(ear)) {
return moans.get(rand.nextInt(moans.size()));
}
return groans.get(rand.nextInt(groans.size()));
}
@Override
public enumFail failure(String input) {
// TODO Auto-generated method stub
return this.failure;
}
@Override
public Boolean completed() {
// TODO Auto-generated method stub
return isComplete;
}
@Override
public AbsAlgPart clone() {
// TODO Auto-generated method stub
return null;
}
@Override
public Boolean itemize() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getMutationLimit() {
// TODO Auto-generated method stub
return 1;
}
}
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum
'''
Failure types:
- ok: no fail
- requip: item should be added
- cloudian: algorithm goes to stand by in its Dclass
- fail: no input
'''
class enumFail(Enum):
fail = "fail"
requip = "requip"
dequip = "dequip"
cloudian = "cloudian"
ok = "ok"
class AbsAlgPart:
@abstractmethod
def action(self, ear: str, skin: str, eye: str) -> str:
'''Returns action string'''
...
# depracated :
# @abstractmethod
# def itemize(self) -> bool:
# '''Equip with item ?'''
# pass
@abstractmethod
def failure(self, input: str) -> enumFail:
'''Failure type only mutatable may use enumFail.fail'''
pass
@abstractmethod
def completed(self) -> bool:
'''Has finished ?'''
pass
@abstractmethod
def clone(self) -> AbsAlgPart:
pass
def getMutationLimit(self) -> int:
return 0
@abstractmethod
def myName(self) -> str:
'''Returns the class name'''
return self.__class__.__name__
import java.util.Hashtable;
public class GrimoireMemento {
private Hashtable<String, String> rootToAPNumDic = new Hashtable<>();
private Hashtable<String, AbsAlgPart> APNumToObjDic = new Hashtable<>();
private AbsDictionaryDB absDictionaryDB;
public GrimoireMemento(AbsDictionaryDB absDictionaryDB) {
super();
this.absDictionaryDB = absDictionaryDB;
}
public AbsAlgPart load(AbsAlgPart obj) {
/*
* load final mutation from memory of obj
*/
String objName = obj.getClass().getSimpleName();
String objRoot = objName.replaceAll("\\d+", "");
// if not in active DB try adding from external DB
if (!rootToAPNumDic.containsKey(objRoot)) {
String temp = this.absDictionaryDB.load(objRoot);
if (!temp.equals("null")) {
rootToAPNumDic.put(objRoot, temp);
}
}
if (!rootToAPNumDic.containsKey(objRoot)) {
rootToAPNumDic.put(objRoot, objName);
return obj;
}
if (rootToAPNumDic.get(objRoot).equals(objName)) {
return obj;
} else {
String APNum = rootToAPNumDic.get(objRoot);
if (APNumToObjDic.containsKey(APNum)) {
return APNumToObjDic.get(APNum).clone();
} else {
loadMutations(obj, objName, objRoot);
return APNumToObjDic.get(APNum).clone();
}
}
}
public void reqquipMutation(String mutationAPName) {
// save mutation
rootToAPNumDic.put(mutationAPName.replaceAll("\\d+", ""), mutationAPName);
this.absDictionaryDB.save(mutationAPName.replaceAll("\\d+", ""), mutationAPName);
}
private void loadMutations(AbsAlgPart obj, String objName, String objRoot) {
// make sure all the AP mutation sets of obj are present
// this assumes the last mutation mutates into the prime mutation
Mutatable mutant;
String end = objName;
do {
APNumToObjDic.put(obj.getClass().getSimpleName(), obj.clone());
mutant = (Mutatable) obj;
obj = mutant.mutation();
}
while (!end.equals(obj.getClass().getSimpleName()));
}
public String simpleLoad(String key){
return this.absDictionaryDB.load(key);
}
public void simpleSave(String key, String value){
if(key.startsWith("AP")||key.isEmpty()||value.isEmpty()){return;}
this.absDictionaryDB.save(key,value);
}
}
import java.util.Hashtable;
public class GrimoireMemento {
//class has been modified, only use chi adaptor for mutation objects to enable save load of final mutations
private Hashtable<String, String> rootToAPNumDic = new Hashtable<>();
private Hashtable<String, Mutatable> APNumToObjDic = new Hashtable<>();
private AbsDictionaryDB absDictionaryDB;
public GrimoireMemento(AbsDictionaryDB absDictionaryDB) {
super();
this.absDictionaryDB = absDictionaryDB;
}
public Mutatable load(Mutatable obj) {
/*
* load final mutation from memory of obj
*/
String objName = obj.getClass().getSimpleName();
String objRoot = objName.replaceAll("\\d+", "");
// if not in active DB try adding from external DB
if (!rootToAPNumDic.containsKey(objRoot)) {
String temp = this.absDictionaryDB.load(objRoot);
if (!temp.equals("null")) {
rootToAPNumDic.put(objRoot, temp);
}
}
if (!rootToAPNumDic.containsKey(objRoot)) {
rootToAPNumDic.put(objRoot, objName);
return obj;
}
if (rootToAPNumDic.get(objRoot).equals(objName)) {
return obj;
} else {
String APNum = rootToAPNumDic.get(objRoot);
if (APNumToObjDic.containsKey(APNum)) {
return APNumToObjDic.get(APNum).clone();
} else {
loadMutations(obj, objName, objRoot);
return APNumToObjDic.get(APNum).clone();
}
}
}
public void reqquipMutation(String mutationAPName) {
// save mutation
rootToAPNumDic.put(mutationAPName.replaceAll("\\d+", ""), mutationAPName);
this.absDictionaryDB.save(mutationAPName.replaceAll("\\d+", ""), mutationAPName);
}
private void loadMutations(Mutatable obj, String objName, String objRoot) {
// make sure all the AP mutation sets of obj are present
// this assumes the last mutation mutates into the prime mutation
Mutatable mutant;
String end = objName;
do {
APNumToObjDic.put(obj.getClass().getSimpleName(), obj.clone());
mutant = (Mutatable) obj;
obj = mutant.mutation();
}
while (!end.equals(obj.getClass().getSimpleName()));
}
public String simpleLoad(String key){
return this.absDictionaryDB.load(key);
}
public void simpleSave(String key, String value){
if(key.startsWith("AP")||key.isEmpty()||value.isEmpty()){return;}
this.absDictionaryDB.save(key,value);
}
}
class t1(Mutatable, ABC):
def mutation(self) -> Mutatable:
print("t1 mutating into t2")
return t2()
def clone(self) -> Mutatable:
print("t1 cloning another t1")
return t1()
class t2(Mutatable, ABC):
def mutation(self) -> Mutatable:
print("t2 mutating into t1")
return t1()
def clone(self) -> Mutatable:
print("t2 cloning another t2")
return t2()
import java.util.ArrayList;
// a step by step plan to achieve a goal
public class Algorithm {
private String goal;
private String representation;
private ArrayList<Mutatable> algParts = new ArrayList<>();
public Algorithm(String goal, String representation, ArrayList<Mutatable> algParts) {
super();
this.goal = goal;
this.representation = representation;
this.algParts = algParts;
}
// *constract with string and goal
public String getGoal() {
return goal;
}
public String getRepresentation() {
return representation;
}
public ArrayList<Mutatable> getAlgParts() {
return algParts;
}
public int getSize() {
return algParts.size();
}
public Algorithm clone() {
ArrayList<Mutatable> parts = new ArrayList<>();
for (Mutatable Mutatable : this.algParts) {
parts.add(Mutatable.clone());
}
return new Algorithm(this.goal, getRepresentation(), parts);
}
}
public class CldBool {
//cloudian : this class is used to provide shadow reference to a boolean variable
private Boolean modeActive = false;
public Boolean getModeActive() {
return modeActive;
}
public void setModeActive(Boolean modeActive) {
this.modeActive = modeActive;
}
}
import java.util.ArrayList;
public class APCldVerbatim extends Mutatable {
/*
* this algorithm part says each past param verbatim
*/
private ArrayList<String> sentences = new ArrayList<String>();
private int at = 0;
private CldBool cldBool;
public APCldVerbatim(CldBool cldBool, String... sentences) {
for (int i = 0; i < sentences.length; i++) {
this.sentences.add(sentences[i]);
}
if (0 == sentences.length) {
at = 30;
}
this.cldBool = cldBool;
this.cldBool.setModeActive(true);
}
public APCldVerbatim(CldBool cldBool, ArrayList<String> list1) {
this.sentences = new ArrayList<String>(list1);
if (0 == this.sentences.size()) {
at = 30;
}
this.cldBool = cldBool;
this.cldBool.setModeActive(true);
}
@Override
public String action(String ear, String skin, String eye) {
// TODO Auto-generated method stub
String axnStr = "";
if (this.at < this.sentences.size()) {
axnStr = this.sentences.get(at);
at++;
}
cldBool.setModeActive(!(at >= this.sentences.size()));
return axnStr;
}
@Override
public enumFail failure(String input) {
// TODO Auto-generated method stub
return enumFail.ok;
}
@Override
public Boolean completed() {
return at >= this.sentences.size();
}
@Override
public Mutatable clone() {
// TODO Auto-generated method stub
return new APCldVerbatim(cldBool, this.sentences);
}
}
package com.yotamarker.lgkotlin1;
import java.util.Hashtable;
/* all action data goes through here
* detects negatives such as : repetition, pain on various levels and failures
* serves as a database for memories, convos and alg generations
* can trigger revenge algs
* checks for % of difference in input for exploration type algs
* */
public class Kokoro {
private String emot = "";
public String getEmot() {
return emot;
}
public void setEmot(String emot) {
this.emot = emot;
}
Hashtable<String, Integer> pain = new Hashtable<>();
public GrimoireMemento grimoireMemento;
public Hashtable<String, String> toHeart = new Hashtable<>();
public Hashtable<String, String> fromHeart = new Hashtable<>();
public Boolean standBy = false;
public Kokoro(AbsDictionaryDB absDictionaryDB) {
super();
this.grimoireMemento = new GrimoireMemento(absDictionaryDB);
}
public int getPain(String BijuuName) {
return pain.getOrDefault(BijuuName, 0);
}
public void in(Chi chi) {
}
public void out(Boolean isCompleted, enumFail failure) {
}
}
public class Chi extends Mutatable {
/*
* an adaptor pattern to the alg part, it also has the kokoro consiousness
* object to be aware throughout the program of what is happening all action
* data goes through this soul.
*/
public Kokoro kokoro;
public String ofSkill;
public Mutatable aPart;
public Chi(Kokoro kokoro, String ofSkill, Mutatable aPart) {
super();
this.kokoro = kokoro;
this.ofSkill = ofSkill;
this.aPart = kokoro.grimoireMemento.load(aPart);
}
public String actualAction(String ear, String skin, String eye) {
return aPart.action(ear, skin, eye);
}
@Override
public String action(String ear, String skin, String eye) {
kokoro.in(this);
String result = actualAction(ear, skin, eye);
kokoro.out(completed(), failure(""));
return result;
}
@Override
public enumFail failure(String input) {
// TODO Auto-generated method stub
return aPart.failure(input);
}
@Override
public Boolean completed() {
// TODO Auto-generated method stub
return aPart.completed();
}
@Override
public Mutatable clone() {
// TODO Auto-generated method stub
return new Chi(kokoro, this.ofSkill, aPart.clone());
}
@Override
public int getMutationLimit() {
// TODO Auto-generated method stub
return aPart.getMutationLimit();
}
@Override
public Mutatable mutation() {
Mutatable mutant = (Mutatable) aPart;
Mutatable tempAP = mutant.mutation();
kokoro.grimoireMemento.reqquipMutation(tempAP.getClass().getSimpleName());
return new Chi(kokoro, this.ofSkill, tempAP);
}
@Override
public String myName() {
return aPart.myName();
}
}
import java.util.ArrayList;
// used to transport algorithms to other classes
public class Neuron {
public ArrayList<Algorithm> algParts = new ArrayList<>();
public ArrayList<Algorithm> negativeAlgParts = new ArrayList<>();
public void empty() {
this.algParts.clear();
this.negativeAlgParts.clear();
}
}
import java.util.ArrayList;
public class DISkillUtils {
public Algorithm verbatimGorithm(Mutatable itte) {
// returns a simple algorithm containing 1 alg part
String representation = "util";
ArrayList<Mutatable> algParts1 = new ArrayList<>();
algParts1.add(itte);
Algorithm algorithm = new Algorithm("util", representation, algParts1);
return algorithm;
}
public Algorithm verbatimGorithm(String algMarker, Mutatable itte) {
// returns a simple algorithm for saying sent parameter
String representation = "util";
ArrayList<Mutatable> algParts1 = new ArrayList<>();
algParts1.add(itte);
Algorithm algorithm = new Algorithm("util", representation, algParts1);
return algorithm;
}
public Algorithm customizedVerbatimGorithm(String algMarker, Mutatable itte) {
// the most stable and advanced algorithm builder
// returns a simple algorithm containing 1 alg part
String representation = "r_" + algMarker;
ArrayList<Mutatable> algParts1 = new ArrayList<>();
algParts1.add(itte);
Algorithm algorithm = new Algorithm(algMarker, representation, algParts1);
return algorithm;
}
public Algorithm customizedVerbatimGorithm(String algMarker, Mutatable... itte) {
// the most stable and advanced algorithm builder
// returns a simple algorithm containing 1 alg part
String representation = "r_" + algMarker;
ArrayList<Mutatable> algParts1 = new ArrayList<>();
for (int i = 0; i < itte.length; i++) {
algParts1.add(itte[i]);
}
Algorithm algorithm = new Algorithm(algMarker, representation, algParts1);
return algorithm;
}
public Algorithm simpleVerbatimAlgorithm(String algMarker, String... sayThis) {
// returns alg that says the word string (sayThis)
return customizedVerbatimGorithm(algMarker, new APVerbatim(sayThis));
}
public Algorithm simpleCloudiandVerbatimAlgorithm(CldBool cldBool, String algMarker, String... sayThis) {
// returns alg that says the word string (sayThis)
return customizedVerbatimGorithm(algMarker, new APCldVerbatim(cldBool, sayThis));
}
public String strContainsList(String str1, ArrayList<String> items) {
// returns the 1st match between words in a string and values in a list.
for (String temp : items) {
if (str1.contains(temp)) {
return temp;
}
}
return "";
}
}
public class DiSkillV2 {
protected Kokoro kokoro; // consciousness, shallow ref class to enable interskill communications
protected DISkillUtils diSkillUtils = new DISkillUtils();
protected Algorithm outAlg = null; // skills output
public DiSkillV2(Kokoro kokoro) {
super();
this.kokoro = kokoro;
}
public void input(String ear, String skin, String eye) {
}
public void output(Neuron noiron) {
if (outAlg != null) {
noiron.algParts.add(outAlg);
outAlg = null;
}
}
public Boolean auto() {
// does this skill also engage by time triggers ? is it also a level > 1 type of
// skill ? if yes
// override me and return true;
return false;
}
}
public class Cerabellum {
// runs an algorithm
private int fin;
private int at;
private enumFail failType;
private Boolean incrementAt = false;
public void advanceInAlg() {
if (incrementAt) {
incrementAt = false;
at++;
if (at == fin) {
isActive = false;
}
}
}
public int getAt() {
return at;
}
public Algorithm alg;
private boolean isActive = false;
private String emot = "";
public String getEmot() {
return emot;
}
public boolean setAlgorithm(Algorithm algorithm) {
if (!isActive && (algorithm.getAlgParts() != null)) {
this.alg = algorithm;
this.at = 0;
this.fin = algorithm.getSize();
this.isActive = true;
this.emot = alg.getAlgParts().get(at).myName(); // updated line
return false;
}
return true;
}
public boolean isActive() {
return isActive;
}
public boolean setActive(Boolean b1) {
return isActive = b1;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
public String act(String ear, String skin, String eye) {
String axnStr = "";
if (!isActive) {
return axnStr;
}
if (at < fin) {
axnStr = alg.getAlgParts().get(at).action(ear, skin, eye);
this.emot = alg.getAlgParts().get(at).myName();
if (alg.getAlgParts().get(at).completed()) {
incrementAt = true;
// at++;
// if (at == fin) {
// isActive = false;
// }
}
}
return axnStr;
}
public int getMutationLimitOfActiveAlgPart() {
return alg.getAlgParts().get(at).getMutationLimit();
}
public enumFail getFailType() {
return alg.getAlgParts().get(at).failure("");
}
}
package com.yotamarker.lgkotlin1;
//D class responsible for exploring :
// learning, mutating algorithms, requiping APs with objects or skill mods
// the sould resides here
public class DExplorer extends DiSkillV2 {
private int failureCounter = 0;
private String prevAP = "";
@Override
public void output(Neuron noiron) {
// TODO Auto-generated method stub
}
@Override
public void input(String ear, String skin, String eye) {
// TODO Auto-generated method stub
}
public void mutate(Cerabellum cera, enumFail failure) {
String AP = cera.getEmot();
/*
* group relies on a naming convention each class in a mutation series must have
* the same class name concated with a number : APMoan1, APMoan2, APMaon3 ...
*/
AP = AP.replaceAll("\\d+", "");
// give up ? :
if (prevAP.contains(AP) && !failure.toString().equals(enumFail.ok.toString())) {
failureCounter++;
if (failureCounter > cera.getMutationLimitOfActiveAlgPart()) {
cera.setActive(false);
// this.failureCounter = 0;
}
}
else {
if (!prevAP.contains(AP)) {
failureCounter = 0;
}
}
prevAP = AP;
switch (failure) {
case fail:
Mutatable mutant = (Mutatable) cera.alg.getAlgParts().get(cera.getAt());
cera.alg.getAlgParts().set(cera.getAt(), mutant.mutation());
break;
case cloudian:
cera.setActive(false);
break;
default:
break;
}
}
}