looks like another boss battle. わくわく suru yo
Moti Barski wrote:Alg cls:
AlgPart
action var : default or learned or chooses
to know if the ap uses an item we can use a naming convention, the ap has item name.
with the exception of special AP like saying and cussing which we can hardcode.
the super replica also needs a position reset()
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 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")) {
}
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()) {
}
return "";
}
}
Code:
package chobit;
import java.util.Hashtable;
import java.util.Stack;
public class SupeReplikaMap {
private Stack<Integer> objPoint = new Stack<Integer>();
// private ArrayList<String> objPointGPS = new ArrayList<String>();
private Hashtable<String, String> PointDefcon = new Hashtable<>();
private Hashtable<String, String> objPointLog = new Hashtable<>();// sensory log
private Compass compass = new Compass();
/*
* friend field //active friend used with skill if any active Mcode(item) field
* active item being used call chobit by name : assume friend|aquire friend|temp
* friend, visual |friend name->assert friend friendAsserted : Boolean general
* call such as hello/hadouken : no need to assert friend
*/
// ***algs
public void input(String item, String defcon, String sensory) {
// save
}
public void recycleThreat(String item, String defcon, String sensory) {
// save and ignore short term memory
}
public void sleep() {
// save as long term memory logs
}
// outputs :
public Integer timeCost() {
return 0;
}
public void getShortTermMemories() {
}
public String slowAlg() {
// describe alg parts inflatedly, than move to next part
return "";
}
public String answer(String question) {
return "";
}
public String warning(String input) {
return "";
}
public String walkThrough(String question) {
return "";
}
public String shortConvo() {
return "";
}
private String lieFilter() {
return "";
}
}
Code:
package chobit;
import java.awt.Point;
import java.util.Hashtable;
import java.util.Stack;
public class SupeReplikaMap {
private Stack<String> objPoint = new Stack<String>();
// private ArrayList<String> objPointGPS = new ArrayList<String>();
private Hashtable<String, String> pointDefcon = new Hashtable<>();
private Hashtable<String, String> objPointLog = new Hashtable<>();// sensory log
private Compass compass = new Compass();
private ZeroTimeGate zeroTimeGate = new ZeroTimeGate(1);
private Point xy = new Point(0, 0);
/*
* friend field //active friend used with skill if any active Mcode(item) field
* active item being used call chobit by name : assume friend|aquire friend|temp
* friend, visual |friend name->assert friend friendAsserted : Boolean general
* call such as hello/hadouken : no need to assert friend
*/
// ***algs
// advance by compass
// reset position to home
public void input(String item, String defcon, String sensory) {
// save
if (zeroTimeGate.isClosed()) {
zeroTimeGate.open();
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
objPointLog.put(xy.toString(), sensory);
}
}
public void recycleThreat(String item, String defcon, String sensory) {
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
objPointLog.put(xy.toString(), sensory);
}
public void sleep() {
// save as long term memory logs
}
// outputs :
public Integer timeCost() {
return 0;
}
public String answer(String question) {
return "";
}
public String warning(String input) {
return "";
}
public String walkThrough(String question) {
return "";
}
}
Code:
package chobit;
import java.awt.Point;
import java.util.Hashtable;
import java.util.Stack;
public class SupeReplikaMap {
private Stack<String> objPoint = new Stack<String>();
// private ArrayList<String> objPointGPS = new ArrayList<String>();
private Hashtable<String, String> pointDefcon = new Hashtable<>();
private Hashtable<String, String> PointLog = new Hashtable<>();// sensory log
private Compass compass = new Compass();
private ZeroTimeGate zeroTimeGate = new ZeroTimeGate(1);
private Point xy = new Point(0, 0);
/*
* friend field //active friend used with skill if any active Mcode(item) field
* active item being used call chobit by name : assume friend|aquire friend|temp
* friend, visual |friend name->assert friend friendAsserted : Boolean general
* call such as hello/hadouken : no need to assert friend
*/
// ***algs
// advance by compass
// reset position to home
public void input(String item, String defcon, String sensory) {
// save
if (zeroTimeGate.isClosed()) {
zeroTimeGate.open();
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
}
public void recycleThreat(String item, String defcon, String sensory) {
// when predicting a goal, or explore traversing
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
public void sleep() {
// save as long term memory logs
}
// outputs :
public Integer timeCost() {
return 0;
}
public String answer(String question) {
switch (question) {
case "describe":
return PointLog.get(xy.toString());
case "what":
return pointDefcon.get(xy.toString());
default:
break;
}
return "";
}
public String warning(String input) {
return "";
}
public String walkThrough(String question) {
return "";
}
}
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 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 (this.soulOutput.isEmpty()) {
return "";
}
if (ear.contains("how")) {
}
String question = strContains(ear, "what");
if (!question.isEmpty()) {
}
question = strContains(ear, "describe", "elaborate");
if (!question.isEmpty()) {
}
if (ear.contains("example")) {
// /JOI example||detail, default for dirty skills
}
if (ear.contains("sleep")) {
}
return "";
}
}
Code:
package chobit;
import java.util.ArrayList;
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;
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 Algorithm soulOutput(String ear) // ear or time
{
String question = strContains(ear, "what", "description", "where", "sleep");
switch (question) {
case "where":
String[] tempArray = (String[]) this.items.toArray();
String tempItem = strContains(ear, tempArray);
return diSkillUtil.verbatimGorithm(new APVerbatim(replikaMap.where(tempItem)));
default:
if (!question.isEmpty()) {
return diSkillUtil.verbatimGorithm(new APVerbatim(replikaMap.answer(question)));
}
break;
}
return null;
}
}
Code:
package chobit;
import java.awt.Point;
import java.util.Hashtable;
import java.util.Stack;
public class SupeReplikaMap {
private Stack<String> objPoint = new Stack<String>();
// private ArrayList<String> objPointGPS = new ArrayList<String>();
private Hashtable<String, String> pointDefcon = new Hashtable<>();
private Hashtable<String, String> PointLog = new Hashtable<>();// sensory log
private Compass compass = new Compass();
private ZeroTimeGate zeroTimeGate = new ZeroTimeGate(1);
private Point xy = new Point(0, 0);
public void input(String item, String defcon, String sensory) {
// save
// TODO point + compass
if (zeroTimeGate.isClosed()) {
zeroTimeGate.open();
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
}
public void recycleThreat(String item, String defcon, String sensory) {
// when predicting a goal, or explore traversing
// TODO point + compass
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
public void sleep() {
// save as long term memory logs
}
// outputs :
public Integer timeCost() {
return 0;
}
public String answer(String question) {
switch (question) {
case "describe":
return PointLog.getOrDefault(xy.toString(), "hey listen");
case "what":
return pointDefcon.getOrDefault(xy.toString(), "hey watch out");
default:
break;
}
return "";
}
public String where(String item) {
String answer = "";
for (String temp : objPoint) {
if (temp.contains(item)) {
return item.replace(temp, "");
} // TODO convert to address
}
return "";
}
public String walkThrough(String question) {
return "";
}
}
Code:
package chobit;
import java.awt.Point;
import java.util.Hashtable;
import java.util.Stack;
public class SupeReplikaMap {
private Stack<String> objPoint = new Stack<String>();
// private ArrayList<String> objPointGPS = new ArrayList<String>();
private Hashtable<String, String> pointDefcon = new Hashtable<>();
private Hashtable<String, String> PointLog = new Hashtable<>();// sensory log
private Hashtable<String, String> logPoint = new Hashtable<>();//traverse log
private Compass compass = new Compass();
private ZeroTimeGate zeroTimeGate = new ZeroTimeGate(1);
private Point xy = new Point(0, 0);
public void input(String item, String defcon, String sensory) {
// save
// TODO point + compass
if (zeroTimeGate.isClosed()) {
zeroTimeGate.open();
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
}
public void recycleThreat(String item, String defcon, String sensory) {
// when predicting a goal, or explore traversing
// TODO point + compass
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
public void sleep() {
// save as long term memory logs
}
// outputs :
public Integer timeCost() {
return 0;
}
public String answer(String question) {
switch (question) {
case "describe":
return PointLog.getOrDefault(xy.toString(), "hey listen");
case "what":
return pointDefcon.getOrDefault(xy.toString(), "hey watch out");
default:
break;
}
return "";
}
public String where(String item) {
String answer = "";
for (String temp : objPoint) {
if (temp.contains(item)) {
return item.replace(temp, "");
} // TODO convert to address
}
return "";
}
public String walkThrough(String question) {
return "";
}
public void logPoint(String log) {
// move point by compass
logPoint.put(log, this.xy.toString());
}
public String getPoint(String log) {
return logPoint.getOrDefault(log,"");
}
}
Admin wrote:the deacon case should have override over non cases.
Code:
public void input(String item, String defcon, String sensory) {
// save
// TODO point + compass
Boolean defconOverride = (pointDefcon.getOrDefault(xy.toString(), "").isEmpty()) && !defcon.isEmpty();
if (zeroTimeGate.isClosed() || defconOverride) {
zeroTimeGate.open();
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
}
Code:
package chobit;
import java.awt.Point;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// returns expression of type theRegex from the string str2Check
public class RegexUtil {
public String regexChecker(String theRegex, String str2Check) {
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return regexMatcher.group().trim();
}
}
return "";
}
public String numberRegex(String str2Check) {
String theRegex = "[-+]?[0-9]{1,13}(\\.[0-9]*)?";
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return regexMatcher.group().trim();
}
}
return "";
}
public String intRegex(String str2Check) {
String theRegex = "[-+]?[0-9]{1,13}";
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return regexMatcher.group().trim();
}
}
return "";
}
public Point pointRegex(String str2Check) {
// "[-+]?[0-9]{1,13}(\\.[0-9]*)?" for double numbers
String theRegex = "[-+]?[0-9]{1,13}";
Point result = new Point(0, 0);
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
result.y = Integer.parseInt(regexMatcher.group().trim());
}
}
String phase2 = str2Check.replace(result.x + "", "");
phase2 = numberRegex(phase2);
result.x = Integer.parseInt(phase2);
return result;
}
public ArrayList<String> regexChecker2(String theRegex, String str2Check) {
// return a list of all matches
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
list.add(regexMatcher.group().trim());
}
}
return list;
}
public String contactRegex(String str2Check) {
// return a list of all matches
String theRegex = "(?<=contact)(.*)";
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return regexMatcher.group().trim();
}
}
return "";
}
public String emailRegex(String str2Check) {
// return a list of all matches
String theRegex = "^([_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{1,6}))?$";
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return regexMatcher.group().trim();
}
}
return "";
}
public String duplicateRegex(String str2Check) {
// return a list of all matches
// String theRegex = "\\b(\\w+)(\\b\\W+\\b\\1\\b)*";
String theRegex = "\\b([\\w\\s']+) \\1\\b"; // set to 1 repeat of a word like hadoken hadoken
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return uniqueWord(regexMatcher.group().trim());
}
}
return "";
}
public String uniqueWord(String str) {
ArrayList<String> list = new ArrayList<String>();
String s[] = str.split(" ");
String p = s[0];
list.add(p);
for (int i = 1; i < s.length; i++) {
if (!(p == s[i])) {
list.add(s[i]);
}
p = s[i];
} // i
return list.get(0);
}
public String afterWord(String word, String str2Check) {
// return a list of all matches
String theRegex = "(?<=" + word + ")(.*)";
ArrayList<String> list = new ArrayList<String>();
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return regexMatcher.group().trim();
}
}
return "";
}
public String phoneRegex1(String str2Check) {
return regexChecker("[0]\\d{2}\\d{4}\\d{3}$", str2Check);
}
public String firstWord(String str2Check) {
String arr[] = str2Check.split(" ", 2);
String firstWord = arr[0]; // the
return firstWord;
}
}
Code:
package chobit;
import java.awt.Point;
import java.util.Hashtable;
import java.util.Stack;
public class SupeReplikaMap {
private Stack<String> objPoint = new Stack<String>();
// private ArrayList<String> objPointGPS = new ArrayList<String>();
private Hashtable<String, String> pointDefcon = new Hashtable<>();
private Hashtable<String, String> PointLog = new Hashtable<>();// sensory log
private Hashtable<String, String> logPoint = new Hashtable<>();// traverse log
private Compass compass = new Compass();
private ZeroTimeGate zeroTimeGate = new ZeroTimeGate(1);
private Point xy = new Point(0, 0);
private RegexUtil regexUtil = new RegexUtil();
public void input(String item, String defcon, String sensory) {
// save
// timegate pause = 1;
zeroTimeGate.setPause(1);
this.xy = pointUpdate(this.xy);
Boolean defconOverride = (pointDefcon.getOrDefault(xy.toString(), "").isEmpty()) && !defcon.isEmpty();
if (zeroTimeGate.isClosed() || defconOverride) {
zeroTimeGate.open();
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
}
public Point strToPoint(String s1) {
return regexUtil.pointRegex(s1);
}
private Point pointUpdate(Point p1) {
Point endPoint = new Point(p1.x, p1.y);
switch (this.compass.getDirection()) {
case 0:
endPoint.y++;
break;
case 2:
endPoint.x++;
break;
case 4:
endPoint.y--;
break;
case 6:
endPoint.x--;
break;
default:
break;
}
return endPoint;
}
public void recycleThreat(String item, String defcon, String sensory) {
// when predicting a goal, or explore traversing
zeroTimeGate.setPause(5);
objPoint.add(xy.toString() + item);
pointDefcon.put(xy.toString(), defcon);
PointLog.put(xy.toString(), sensory);
}
public void sleep() {
// save as long term memory logs
}
// outputs :
public Integer timeCost() {
return 0;
}
public String answer(String question) {
switch (question) {
case "describe":
return PointLog.getOrDefault(xy.toString(), "hey listen");
case "what":
return pointDefcon.getOrDefault(xy.toString(), "hey watch out");
default:
break;
}
return "";
}
public String where(String item) {
String answer = "";
for (String temp : objPoint) {
if (temp.contains(item)) {
return item.replace(temp, "");
} // TODO convert to address
}
return "";
}
public String walkThrough(String question) {
return "";
}
public void logPoint(String log) {
// move point by compass
logPoint.put(log, this.xy.toString());
}
public String getPoint(String log) {
return logPoint.getOrDefault(log, "");
}
public void deleteKey(String pointItem) {
objPoint.remove(pointItem);
/*
* on return home delete failed pointTransportItem.
*/
// TODO sql side
}
public void setHome() {
this.xy = new Point(0, 0);
}
}