battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

battle programming a forum for elite programmers with extreme will power to sharpen their skills

descriptiontrigger gate series Emptytrigger gate series

more_horiz
this triggers aim to save coding time and set AI behaviors and personality traits.

parent class :

Code:

public abstract class AbsTrg {
   // sub classes names should start with Trg
   public abstract int trigger(Boolean trigger);

   // trigger reset, implement if needed
   public abstract void reset();
}


TrgCounter

Code:

public class TrgCounter extends AbsTrg {
   private CountDownGate cdg;
   private Boolean Mode = false;
   private int score = 0;

   public TrgCounter(int tolerance, Boolean mode) {
      super();
      this.cdg = new CountDownGate(tolerance);
      Mode = mode;
   }

   public TrgCounter(int tolerance) {
      super();
      this.cdg = new CountDownGate(tolerance);
   }
   @Override
   public int trigger(Boolean trigger) {
      if (!trigger) {
         return 0;
      }
      if (!cdg.countingDown()) {
         Mode = !Mode;
         cdg.reset();
         score++;
         if (score > 10000) {
            score = 0;
         }
      }
      return Mode ? 1 : 0;
   }

   public int getScore() {
      // what is your [] score
      return score;
   }

   @Override
   public void reset() {
      // bad girl
      Mode = false;
      this.cdg = new CountDownGate(10);
   }

   public void reset2() {
      // good girl
      Mode = true;
      this.cdg = new CountDownGate(10);
   }
   public void increaseBias() {
      // take it
      this.cdg = new CountDownGate(cdg.getLimit() + 10);
   }

   public int getMode() {
      return Mode ? 1 : 0;
   }
}


examle test :
TrgCounter tc = new TrgCounter(10);
for (int i = 0; i < 50; i++) {
System.out.println(tc.trigger(true) == 1 ? "yandere" : "tsundere");
}

tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
yandere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
tsundere
yandere

_________________
MB over and out emp it up

descriptiontrigger gate series EmptyRe: trigger gate series

more_horiz
TrgDate : can be used for birthdays and such

Code:

public class TrgDate extends AbsTrg {
   // this trigger will sent 1 only once in the preset day
   private PlayGround pl = new PlayGround();
   private Boolean sent = false;
   private String dDay = "";
   @Override
   public int trigger(Boolean trigger) {
      if (!trigger) {
         return 0;
      }
      String today = pl.getMonthAsInt() + " " + pl.getDayOfTheMonthAsInt();
      if (dDay.equals(today) && !sent) {
         sent = true;
         return 1;
      }
      if (!dDay.equals(today)) {
         sent = false;
      }
      return 0;
   }

   @Override
   public void reset() {
      sent = false;
   }

   public void setDate() {
      dDay = pl.getMonthAsInt() + " " + pl.getDayOfTheMonthAsInt();
   }

   public void setDate(String dateOfMonth1, String month1) {
      dDay = dateOfMonth1 + " " + month1;
   }
}


TrgHourly
//can be used for affection displays towards the user

Code:

public class TrgHourly extends AbsTrg {
   private PlayGround pl = new PlayGround();
   private int prevHour = 30;

   @Override
   public int trigger(Boolean trigger) {
      if (!trigger) {
         return 0;
      }
      int t = pl.getHoursAsInt();
      if (t != prevHour) {
         prevHour = t;
         return 1;
      }
      return 0;
   }
   @Override
   public void reset() {
      prevHour = 30;
   }
}


time stamp trigger :

Code:

import java.util.ArrayList;

public class TrgTimeStamps extends AbsTrg {
   /*
    * this trigger becomes active only at the time stamp times input regex
    * examples: "05:00", "19:05";
    */
   private PlayGround pl = new PlayGround();
   private ArrayList<String> times = new ArrayList<String>();
   private String sent = "";

   public TrgTimeStamps(String... trigerringTimeStamps) {
      for (int i = 0; i < trigerringTimeStamps.length; i++) {
         times.add(trigerringTimeStamps[i]);
      }
   }

   @Override
   public int trigger(Boolean trigger) {
      if (!trigger) {
         return 0;
      }
      String rightNow = pl.getCurrentTimeStamp();
      if (!sent.equals(rightNow)) {
         sent = "";
         if (times.contains(rightNow)) {
            sent = rightNow;
            return 1;
         }
      }
      return 0;
   }

   @Override
   public void reset() {
      sent = "";
   }
}


chii

_________________
MB over and out emp it up
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum