@kurosen
hadouken
hadouken
kurosen wrote:also need to reset the alg to null at the start of the input stage
Code:
package chobit;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Queue;
public class TheSkill extends DISkill {
protected RegexUtil regexUtil = new RegexUtil();
protected DISkillUtils diSkillUtil = new DISkillUtils();
protected PlayGround playGround = new PlayGround();
protected CloudianV2 cloudian = new CloudianV2();
private MCodes mCodes = new MCodes(); // items
private ReplikaMap replikaMap = new ReplikaMap();
private Person friend = new Person(); // if you deal with several friends handle it in the sub class
private Boolean friendUpdatable = false;
private ArrayList<String> items = new ArrayList<String>();
private String item = "";
protected AbsDefConTranslator absDefConTranslator;
private int defcon = 0;
protected Algorithm outputAlg = null;
protected Queue<String> soulOutput = new PriorityQueue<>();
private int soulHP = 2;
private Boolean replenishSoulHp = true;
public TheSkill(Kokoro kokoro, AbsDefConTranslator absDefConTranslator, ArrayList<String> items) {
super(kokoro);
this.items = items;
this.absDefConTranslator = absDefConTranslator;
}
@Override
public void input(String ear, String skin, String eye) {
detectFriend(ear);
}
@Override
public void output(Neuron noiron) {
if (!isNull(this.outputAlg)) {
noiron.algParts.add(this.outputAlg);
this.outputAlg = null;
}
// after this, if there is no reference to the object,
// it will be deleted by the garbage collector
}
private boolean isNull(Object obj) {
return obj == null;
}
private void trgAction(String ear, String skin, String eye) {
// sensory, souled, predicted
}
private void trgExplore(String ear, String skin, String eye) {
// timed
// Exploration and learning, Alg efficiancy tests and sort
}
private void trgPreserve(String ear, String skin, String eye) {
// timed
// items and persons preservation, causes being annoyed if repeated in day
}
protected Algorithm makeFriend() {
return diSkillUtil.verbatimGorithm(new APVerbatim("what is your name"));
}
protected void friendUpdate(String ear) {
String temp = regexUtil.phoneRegex1(ear);
if(!temp.isEmpty()) {friend.setPhone(temp);}
temp = regexUtil.emailRegex(ear);
if(!temp.isEmpty()) {friend.setEmail(temp);}
temp = regexUtil.afterWord("i am ", ear);
if (temp.isEmpty()) {
temp = regexUtil.afterWord("my name is ", ear);
}
if (!temp.isEmpty()) {
friend.setName(temp);
friend.setActive(true);
}
temp = regexUtil.duplicateRegex(ear);
if (!temp.isEmpty()) {
friend.setJutsu(temp);
friend.setActive(true);
}
}
// key stuff detection and handling
protected void detectFriend(String ear) {
if (playGround.getMinutesAsInt() % 2 == 0) {
friendUpdatable = false;
}
Boolean friendRequest = (ear.contains("friends") || ear.contains("my name is")) && !this.friend.getActive();
if (friendRequest) {
kokoro.toHeart.put("Me", "introduce");
}
if (ear.contains(friend.getName()) || (ear.contains(friend.getJutsu())) || friendRequest)// or friend visual
{
friendUpdatable = true;
}
if (friendUpdatable) {
friendUpdate(ear);
}
}
protected String currentItem(String ear, String skin, String eye) {
for (String item : items) {
if (eye.contains(item)) {
return item;
}
}
for (String item : items) {
if (skin.contains(item)) {
return item;
}
}
for (String item : items) {
if (ear.contains(item)) {
return item;
}
}
return "";
}
public static String strContains(String str1, String... a) {
for (String temp : a) {
if (str1.contains(temp)) {
return temp;
}
}
return "";
}
protected void inputToSoul(String ear, String skin, String eye) {
String sensory = ear;
if (sensory.isEmpty()) {
sensory = skin;
}
if (sensory.isEmpty()) {
sensory = eye;
}
if (!this.item.isEmpty()) {
this.replikaMap.input(item, defcon, sensory);
}
}
protected String soulOutput(String ear) // ear or time
{
if (ear.contains("yes")) {
soulHP++;
}
if (this.soulOutput.isEmpty()) {
return "";
}
if (ear.contains("how")) {
}
String question = strContains(ear, "who", "what", "when", "where", "why", "which");
if (!question.isEmpty()) {
}
if (ear.contains("example")) {
// /JOI example||detail, default for dirty skills
}
if (ear.contains("sleep")) {
}
if (ear.contains("story")) {
// time trg
}
// default : imprint fresh memories, check not in friend memory.
if (!this.soulOutput.isEmpty()) {
soulHP--;
}
replenishSoulHP();
return "";
}
private void replenishSoulHP() {
int tempMinute = playGround.getMinutesAsInt();
if (tempMinute != 1) {
replenishSoulHp = true;
return;
}
if ((tempMinute == 1) && replenishSoulHp) {
soulHP = 2;
replenishSoulHp = false;
}
}
protected Algorithm mainOutput() {
// overridde me
return null;
}
}
Code:
package chobit;
import java.util.Calendar;
import java.util.Date;
public class ZeroTimeGate {
// a gate that only opens x minutes after it has been set
private int pause = 1;
private Date openedGate = new Date();
private Date checkPoint = new Date();
public ZeroTimeGate(int minutes) {
super();
this.pause = minutes;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
}
public ZeroTimeGate() {
}
public Boolean isClosed() {
return openedGate.before(new Date());
}
public void open() {
this.openedGate = addMinutesToJavaUtilDate(new Date(), pause);
}
public void open(int minutes) {
Date now = new Date();
openedGate = addMinutesToJavaUtilDate(now, minutes);
}
private Date addMinutesToJavaUtilDate(Date date, int minutes) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, minutes);
return calendar.getTime();
}
public void setPause(int pause) {
if (pause < 60 && pause > 0) {
this.pause = pause;
}
}
public void resetCheckPoint() {
this.checkPoint = new Date();
}
public int givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen() {
Date now = new Date();
long diff = now.getTime() - this.checkPoint.getTime();
long diffSeconds = diff / 1000 % 60;
// long diffMinutes = diff / (60 * 1000) % 60;
// long diffHours = diff / (60 * 60 * 1000) % 24;
// long diffDays = diff / (24 * 60 * 60 * 1000);
// System.out.print(diffDays + " days, ");
// System.out.print(diffHours + " hours, ");
// System.out.print(diffMinutes + " minutes, ");
// System.out.print(diffSeconds + " seconds.");
return (int) diffSeconds;
}
}
kurosen wrote:lets continue tomorow, I'm pretty tired tbh
Code:
public void input(String ear, String skin, String eye) {
detectFriend(ear);
this.outputAlg = this.absDefConTranslator.getDefcon(ear, skin, eye);
}
Code:
public void input(String item, String defcon, String sensory) {
// save
}
Code:
protected void inputToSoul(String ear, String skin, String eye) {
String sensory = ear;
String currentDefcon = this.absDefConTranslator.getDefconTranslator().getSpecificDefcom(ear, skin, eye);
if (currentDefcon.isEmpty()) {
currentDefcon = absDefConTranslator.getDefconTranslator().aquiredTarget();
}
if (sensory.isEmpty()) {
sensory = skin;
}
if (sensory.isEmpty()) {
sensory = eye;
}
if (!this.item.isEmpty()) {
this.replikaMap.input(item, currentDefcon, sensory);
}
}
Code:
@Override
public void input(String ear, String skin, String eye) {
detectFriend(ear);
//func1 :
this.outputAlg = this.absDefConTranslator.getDefcon(ear, skin, eye);
inputToSoul(ear, skin, eye);
if(outputAlg!=null) {return;}
//func2
triggeredAlgs(ear,skin,eye);
if(isNull(outputAlg)) {return;}
}
private void triggeredAlgs(String ear, String skin, String eye) {
trgAction(ear,skin,eye);
if(isNull(outputAlg)) {return;}
trgExplore(ear, skin, eye);
if(isNull(outputAlg)) {return;}
trgPreserve(ear, skin, eye);
}
Moti Barski wrote:finish the framework func 1st
Code:
@Override
public void input(String ear, String skin, String eye) {
detectFriend(ear);
// func1 :
this.outputAlg = this.absDefConTranslator.getDefcon(ear, skin, eye);
inputToSoul(ear, skin, eye);
if (outputAlg != null) {
return;
}
// func2
triggeredAlgs(ear, skin, eye);
if (isNull(outputAlg)) {
return;
}
// func3
soulOutput(ear);
}
Code:
package chobit;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Queue;
public abstract class TheSkill extends DISkill {
protected RegexUtil regexUtil = new RegexUtil();
protected DISkillUtils diSkillUtil = new DISkillUtils();
protected PlayGround playGround = new PlayGround();
protected CloudianV2 cloudian = new CloudianV2();
private MCodes mCodes = new MCodes(); // items
private ReplikaMap replikaMap = new ReplikaMap();
private Person friend = new Person(); // if you deal with several friends handle it in the sub class
private Boolean friendUpdatable = false;
private ArrayList<String> items = new ArrayList<String>();
private String item = "";
protected AbsDefConTranslator absDefConTranslator;
private int defcon = 0;
protected Algorithm outputAlg = null;
protected Queue<String> soulOutput = new PriorityQueue<>();
private int soulHP = 2;
private Boolean replenishSoulHp = true;
public TheSkill(Kokoro kokoro, AbsDefConTranslator absDefConTranslator, ArrayList<String> items) {
super(kokoro);
this.items = items;
this.absDefConTranslator = absDefConTranslator;
}
@Override
public void input(String ear, String skin, String eye) {
detectFriend(ear);
// func1 :
this.outputAlg = this.absDefConTranslator.getDefcon(ear, skin, eye);
inputToSoul(ear, skin, eye);
if (outputAlg != null) {
return;
}
// func2
triggeredAlgs(ear, skin, eye);
if (isNull(outputAlg)) {
return;
}
// func3
soulOutput(ear);
}
private void triggeredAlgs(String ear, String skin, String eye) {
trgAction(ear, skin, eye);
if (isNull(outputAlg)) {
return;
}
trgExplore(ear, skin, eye);
if (isNull(outputAlg)) {
return;
}
trgPreserve(ear, skin, eye);
}
@Override
public void output(Neuron noiron) {
if (!isNull(this.outputAlg)) {
noiron.algParts.add(this.outputAlg);
this.outputAlg = null;
}
// after this, if there is no reference to the object,
// it will be deleted by the garbage collector
}
private boolean isNull(Object obj) {
return obj == null;
}
protected abstract void trgAction(String ear, String skin, String eye);
// sensory, souled(kokoro cls directives), predicted
protected abstract void trgExplore(String ear, String skin, String eye);
// timed
// Exploration and learning, Alg efficiancy tests and sort
protected abstract void trgPreserve(String ear, String skin, String eye);
// timed
// items and persons preservation, causes being annoyed if repeated in day
protected Algorithm makeFriend() {
return diSkillUtil.verbatimGorithm(new APVerbatim("what is your name"));
}
protected void friendUpdate(String ear) {
String temp = regexUtil.phoneRegex1(ear);
if(!temp.isEmpty()) {friend.setPhone(temp);}
temp = regexUtil.emailRegex(ear);
if(!temp.isEmpty()) {friend.setEmail(temp);}
temp = regexUtil.afterWord("i am ", ear);
if (temp.isEmpty()) {
temp = regexUtil.afterWord("my name is ", ear);
}
if (!temp.isEmpty()) {
friend.setName(temp);
friend.setActive(true);
}
temp = regexUtil.duplicateRegex(ear);
if (!temp.isEmpty()) {
friend.setJutsu(temp);
friend.setActive(true);
}
}
// key stuff detection and handling
protected void detectFriend(String ear) {
if (playGround.getMinutesAsInt() % 2 == 0) {
friendUpdatable = false;
}
Boolean friendRequest = (ear.contains("friends") || ear.contains("my name is")) && !this.friend.getActive();
if (friendRequest) {
kokoro.toHeart.put("Me", "introduce");
}
if (ear.contains(friend.getName()) || (ear.contains(friend.getJutsu())) || friendRequest)// or friend visual
{
friendUpdatable = true;
}
if (friendUpdatable) {
friendUpdate(ear);
}
}
protected String currentItem(String ear, String skin, String eye) {
for (String item : items) {
if (eye.contains(item)) {
return item;
}
}
for (String item : items) {
if (skin.contains(item)) {
return item;
}
}
for (String item : items) {
if (ear.contains(item)) {
return item;
}
}
return "";
}
public static String strContains(String str1, String... a) {
for (String temp : a) {
if (str1.contains(temp)) {
return temp;
}
}
return "";
}
protected void inputToSoul(String ear, String skin, String eye) {
String sensory = ear;
String currentDefcon = this.absDefConTranslator.getDefconTranslator().getSpecificDefcom(ear, skin, eye);
if (currentDefcon.isEmpty()) {
currentDefcon = absDefConTranslator.getDefconTranslator().aquiredTarget();
}
if (sensory.isEmpty()) {
sensory = skin;
}
if (sensory.isEmpty()) {
sensory = eye;
}
if (!this.item.isEmpty()) {
this.replikaMap.input(item, currentDefcon, sensory);
}
}
protected String soulOutput(String ear) // ear or time
{
if (ear.contains("yes")) {
soulHP++;
}
if (this.soulOutput.isEmpty()) {
return "";
}
if (ear.contains("how")) {
}
String question = strContains(ear, "who", "what", "when", "where", "why", "which");
if (!question.isEmpty()) {
}
if (ear.contains("example")) {
// /JOI example||detail, default for dirty skills
}
if (ear.contains("sleep")) {
}
if (ear.contains("story")) {
// time trg
}
// default : imprint fresh memories, check not in friend memory.
if (!this.soulOutput.isEmpty()) {
soulHP--;
}
replenishSoulHP();
return "";
}
private void replenishSoulHP() {
int tempMinute = playGround.getMinutesAsInt();
if (tempMinute != 1) {
replenishSoulHp = true;
return;
}
if ((tempMinute == 1) && replenishSoulHp) {
soulHP = 2;
replenishSoulHp = false;
}
}
protected Algorithm mainOutput() {
// overridde me
return null;
}
}
Code:
package chobit;
import java.util.ArrayList;
import java.util.Stack;
public class DefconTranslator {
private String input = "";
private Stack<String> inputStack = new Stack<String>();
private ArrayList<String> extraDefcons = new ArrayList<String>();// extra defcons
private ZeroTimeGate zeroTimeGate = new ZeroTimeGate(1);
private RegexUtil regexUtil = new RegexUtil();
private String target = "";
public DefconTranslator(ArrayList<String> extraDefcons) {
super();
this.extraDefcons = extraDefcons;
}
public String getSpecificDefcom(String ear, String skin, String eye) {
for (String item : extraDefcons) {
if (eye.contains(item)) {
return item;
}
}
for (String item : extraDefcons) {
if (skin.contains(item)) {
return item;
}
}
for (String item : extraDefcons) {
if (ear.contains(item)) {
return item;
}
}
return "";
}
public String aquiredTarget() {
// for (String item : inputStack) {
// if (eye.contains(item)) {
// return item;
// }
// }
// for (String item : inputStack) {
// if (skin.contains(item)) {
// return item;
// }
// }
// for (String item : inputStack) {
// if (ear.contains(item)) {
// return item;
// }
// }
return target;
}
// get unique defcon
public int getDefcon(String ear, String skin, String eye) {
// override this methode in subclass per skill
this.target = "";
if (zeroTimeGate.isClosed()) {
if (listInStrEye(ear, skin, eye)) {
zeroTimeGate.open();
target = regexUtil.firstWord(eye);
inputStack.push(target);
return 1;
}
if (listInStrEar(ear, skin, eye)) {
zeroTimeGate.open();
target = regexUtil.afterWord("it is", ear);
if (!target.isEmpty()) {
inputStack.push(target);
}
return 2;
}
if (listInStrLearnedEar(ear, skin, eye)) {
zeroTimeGate.open();
// set target from regex
// send alg
// stuck clear;return alg
target = "deduced: " + regexUtil.afterWord("it is", ear);
if (target.isEmpty()) {
return 3;
}
inputStack.clear();
}
if (listInStrLearnedEye(ear, skin, eye)) {
zeroTimeGate.open();
target = "deduced: " + regexUtil.firstWord(eye);
inputStack.clear();
return 4;
// set target from regex
// send alg
// stuck clear;return alg
}
}
return 0;
}
private Boolean listInStrEye(String ear, String skin, String eye) {
for (String string : extraDefcons) {
if (skin.contains(string)) {
return true;
}
}
for (String string : extraDefcons) {
if (eye.contains(string)) {
return true;
}
}
return false;
}
private Boolean listInStrEar(String ear, String skin, String eye) {
for (String string : extraDefcons) {
if (ear.contains(string)) {
return true;
}
}
return false;
}
private Boolean listInStrLearnedEar(String ear, String skin, String eye) {
for (String string : inputStack) {
if (ear.contains(string)) {
return true;
}
}
return false;
}
private Boolean listInStrLearnedEye(String ear, String skin, String eye) {
for (String string : inputStack) {
if (eye.contains(string)) {
return true;
}
}
return false;
}
}