/*
* this class enables time triggered actions. algorithmic logic examplified with
* the bark action: the AGI will bark at some time, and continue doing so every
* hour till the user replies with his signature catch frase. thus the AGI will
* know the time to expect him home. next she will reply happily. the bark is
* the alg while the happy reply is the alter alg.
*/
DIAutomatic
APBark
modded Person class with 1 line of default value for fast testing
added getFutureHour func to playground class
add skill to the Chobit class :
dClassesLv1.add(new DIAutomatic(kokoro, master));
* this class enables time triggered actions. algorithmic logic examplified with
* the bark action: the AGI will bark at some time, and continue doing so every
* hour till the user replies with his signature catch frase. thus the AGI will
* know the time to expect him home. next she will reply happily. the bark is
* the alg while the happy reply is the alter alg.
*/
DIAutomatic
Code:
package chobit;
import java.util.ArrayList;
import java.util.Arrays;
public class DIAutomatic extends DISkill {
/*
* this class enables time triggered actions. algorithmic logic examplified with
* the bark action: the AGI will bark at some time, and continue doing so every
* hour till the user replies with his signature catch frase. thus the AGI will
* know the time to expect him home. next she will reply happily. the bark is
* the alg while the happy reply is the alter alg.
*/
public Person master;
int algMode[] = new int[1]; // mode of alg per algs: 0,1 alg,alter alg
int algTime[] = new int[1]; // alg trigger time per alg(hence array).
String algTosend = "";
private PlayGround playGround = new PlayGround();
public DIAutomatic(Kokoro kokoro, Person master) {
super(kokoro);
this.master = master;
Arrays.fill(algMode, 0);
algTime[0] = playGround.getHoursAsInt();
}
@Override
public void input(String ear, String skin, String eye) {
int hour = playGround.getHoursAsInt();
for (int i = 0; i < algMode.length; i++) {
if (algMode[i] == 0) {
if (algTime[i] == hour) {
algTime[i] = playGround.getFutureHour(algTime[i], 1);
algTosend = i + "";
specialAlgAction(i);
return;
}
if (alterAlg(i, ear, skin, eye)) {
algTime[i] = hour;
algMode[i] = 1;
break;
}
} else {
if (algTime[i] != hour) {
algMode[i] = 0;
}
}
}
if (!algTosend.isEmpty()) {
this.setSentAlg(true);
}
}
@Override
public void output(Neuron noiron) {
switch (algTosend) {
case "0":
barkAlg(noiron);
break;
case "0mode2":
masterGreetAlg(noiron);
break;
default:
break;
}
algTosend = "";
}
protected void specialAlgAction(int algNumber) {
switch (algNumber) {
case 0:
master.setActive(false);
break;
default:
break;
}
}
protected Boolean alterAlg(int algNumber, String ear, String skin, String eye) {
switch (algNumber) {
case 0:
if (ear.contains(master.getJutsu()) && !master.getActive()) {
master.setActive(true);
algTosend = algNumber + "mode2";
return true;
}
break;
default:
break;
}
return false;
}
private void barkAlg(Neuron noiron) {
// example timed alg
AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APBark(3, master));
String representation = "bark";
ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
algParts1.add(itte);
Algorithm algorithm = new Algorithm("bark", representation, algParts1);
noiron.algParts.add(algorithm);
}
private void masterGreetAlg(Neuron noiron) {
// example alter alg, to fire when respective conditions were met and after a
// timed alg was fired.
AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APSay(1, "i missed you"));
String representation = "welcome";
ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
algParts1.add(itte);
Algorithm algorithm = new Algorithm("welcome", representation, algParts1);
noiron.algParts.add(algorithm);
}
}
APBark
Code:
package chobit;
public class APBark extends AbsAlgPart {
// bark x times
// pause y times
// cycle z times
// or till user present
private int pauseCounter;
private int barkCounter;
private int pauselim;
private int barklim;
private int stopCounter;
private String bark;
public APBark(int stopCounter, Person master) {
super();
this.stopCounter = stopCounter * 2;
this.master = master;
pauselim = 4;
barklim = 3;
pauseCounter = pauselim;
barkCounter = barklim;
bark = "user";
}
public APBark(int stopCounter, String bark, Person master) {
super();
this.stopCounter = stopCounter;
pauselim = 4;
barklim = 3;
pauseCounter = pauselim;
barkCounter = barklim;
this.bark = bark;
this.master = master;
}
public APBark(int pauselim, int barklim, int stopCounter, String bark, Person master) {
super();
this.pauselim = pauselim;
this.barklim = barklim;
this.barkCounter = barklim;
this.stopCounter = stopCounter;
this.bark = bark;
this.master = master;
}
private Boolean barkMode = true;
private Person master;
@Override
public String action(String ear, String skin, String eye) {
// TODO Auto-generated method stub
if (ear.contains(master.getJutsu())) {
stopCounter = 0;
return "";
}
if (barkMode) {
barkCounter--;
if (barkCounter < 1) {
barkMode = !barkMode;
pauseCounter = pauselim;
stopCounter--;
}
return bark;
} else {
pauseCounter--;
if (pauseCounter < 1) {
barkMode = !barkMode;
barkCounter = barklim;
stopCounter--;
}
return "";
}
}
@Override
public Boolean itemize() {
// TODO Auto-generated method stub
return false;
}
@Override
public enumFail failure(String input) {
// TODO Auto-generated method stub
return enumFail.ok;
}
@Override
public Boolean completed() {
// TODO Auto-generated method stub
return stopCounter < 1;
}
@Override
public AbsAlgPart clone() {
return new APBark(this.pauselim, this.barklim, this.stopCounter, this.bark, this.master);
}
}
modded Person class with 1 line of default value for fast testing
Code:
package chobit;
public class Person {
private String name = "";
private Boolean active = true;
private String phone = "";
private String skill = "";
private String profession = "";
private String jutsu = "hadouken";
// location
private String email = "";
private String id = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getSkill() {
return skill;
}
public void setSkill(String skill) {
this.skill = skill;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
public String getJutsu() {
return jutsu;
}
public void setJutsu(String jutsu) {
this.jutsu = jutsu;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
added getFutureHour func to playground class
Code:
package chobit;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
// times and stuff
public class PlayGround {
// int foo = Integer.parseInt(myString);
public String getCurrentTimeStamp() {
// SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
// dd/MM/yyyy
SimpleDateFormat sdfDate = new SimpleDateFormat("HH:mm");// dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
return strDate;
}
public String getMinutes() {
// SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
// dd/MM/yyyy
SimpleDateFormat sdfDate = new SimpleDateFormat("mm");// dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
return strDate;
}
public String getSeconds() {
// SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
// dd/MM/yyyy
SimpleDateFormat sdfDate = new SimpleDateFormat("ss");// dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
return strDate;
}
public String getDayOfDWeek() {
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
return convertToDay(dayOfWeek);
}
private String convertToDay(Integer d) {
String result = "";
switch (d) {
case 1:
result = "sunday";
break;
case 2:
result = "monday";
break;
case 3:
result = "tuesday";
break;
case 4:
result = "wednesday";
break;
case 5:
result = "thursday";
break;
case 6:
result = "friday";
break;
case 7:
result = "saturday";
break;
default:
break;
}
return result;
}
public String getSpecificTime(enumTimes timeType) {
// SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
// dd/MM/yyyy
SimpleDateFormat sdfDate;
String format = "";
switch (timeType) {
case DATE:
Calendar cal = Calendar.getInstance();
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int Month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
return translateMonthDay(dayOfMonth) + " " + translateMonth(Month + 1) + " " + year;
case HOUR:
format = "HH";
break;
case SECONDS:
format = "ss";
break;
case MINUTES:
format = "mm";
break;
case YEAR:
format = "yyyy";
break;
default:
break;
}
sdfDate = new SimpleDateFormat(format);
Date now = new Date();
String strDate = sdfDate.format(now);
return strDate;
}
public int getSecondsAsInt() {
// SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
// dd/MM/yyyy
SimpleDateFormat sdfDate = new SimpleDateFormat("ss");// dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
return Integer.parseInt(strDate);
}
public int getMinutesAsInt() {
// SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
// dd/MM/yyyy
SimpleDateFormat sdfDate = new SimpleDateFormat("mm");// dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
return Integer.parseInt(strDate);
}
public int getHoursAsInt() {
// SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
// dd/MM/yyyy
SimpleDateFormat sdfDate = new SimpleDateFormat("HH");// dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
return Integer.parseInt(strDate);
}
public String getFutureInXMin(int x) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, x);
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
return df.format(cal.getTime());
}
public int getFutureHour(int startHour, int addedHours) {
return (startHour + addedHours) % 25;
}
public String getFutureFromXInYMin(int x, String y) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
try {
cal.setTime(sdf.parse(y));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // all done
cal.add(Calendar.MINUTE, x);
return sdf.format(cal.getTime());
}
public String translateMonth(int month1) {
String dMonth = "";
switch (month1) {
case 1:
dMonth = "january";
break;
case 2:
dMonth = "February";
break;
case 3:
dMonth = "March";
break;
case 4:
dMonth = "April";
break;
case 5:
dMonth = "May";
break;
case 6:
dMonth = "June";
break;
case 7:
dMonth = "July";
break;
case 8:
dMonth = "August";
break;
case 9:
dMonth = "September";
break;
case 10:
dMonth = "October";
break;
case 11:
dMonth = "November";
break;
case 12:
dMonth = "December";
break;
default:
break;
}
return dMonth;
}
public String translateMonthDay(int day1) {
String dday = "";
switch (day1) {
case 1:
dday = "first_of";
break;
case 2:
dday = "second_of";
break;
case 3:
dday = "third_of";
break;
case 4:
dday = "fourth_of";
break;
case 5:
dday = "fifth_of";
break;
case 6:
dday = "sixth_of";
break;
case 7:
dday = "seventh_of";
break;
case 8:
dday = "eighth_of";
break;
case 9:
dday = "nineth_of";
break;
case 10:
dday = "tenth_of";
break;
case 11:
dday = "eleventh_of";
break;
case 12:
dday = "twelveth_of";
break;
case 13:
dday = "thirteenth_of";
break;
case 14:
dday = "fourteenth_of";
break;
case 15:
dday = "fifteenth_of";
break;
case 16:
dday = "sixteenth_of";
break;
case 17:
dday = "seventeenth_of";
break;
case 18:
dday = "eighteenth_of";
break;
case 19:
dday = "nineteenth_of";
break;
case 20:
dday = "twentyth_of";
break;
case 21:
dday = "twentyfirst_of";
break;
case 22:
dday = "twentysecond_of";
break;
case 23:
dday = "twentythird_of";
break;
case 24:
dday = "twentyfourth_of";
break;
case 25:
dday = "twentyfifth_of";
break;
case 26:
dday = "twentysixth_of";
break;
case 27:
dday = "twentyseventh_of";
break;
case 28:
dday = "twentyeighth_of";
break;
case 29:
dday = "twentynineth_of";
break;
case 30:
dday = "thirtyth_of";
break;
case 31:
dday = "thirtyfirst_of";
break;
default:
break;
}
return dday;
}
}
add skill to the Chobit class :
dClassesLv1.add(new DIAutomatic(kokoro, master));