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


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

 DiB8Tri a hunger skill for the living grimoire

Go down 
AuthorMessage
Moti Barski
super
super
Moti Barski

Posts : 568
Join date : 2011-08-02

DiB8Tri a hunger skill for the living grimoire Empty
PostSubject: DiB8Tri a hunger skill for the living grimoire   DiB8Tri a hunger skill for the living grimoire EmptyFri Mar 05, 2021 5:24 am

Code:
package chobit;

public class DiB8Tri extends DISkill {
   private int powerLevel = 90;
   private RegexUtil regexUtil = new RegexUtil();
   private Boolean fastCharging = false;
   private Boolean slowCharging = false;
   private Boolean wasCharging = false;
   private String outStr = "";
   private DISkillUtils diSkillUtils = new DISkillUtils();
   private String lastMeal = "i haven't eaten since i woke up";
   private PlayGround playGround = new PlayGround();
   private Boolean lc = true;// was the last charge fast ?
   public DiB8Tri(Kokoro kokoro) {
      super(kokoro);
   }

   @Override
   public void input(String ear, String skin, String eye) {
      if (ear.isEmpty() && skin.isEmpty()) {
         return;
      }
      // get power level
      int prevPower = powerLevel;
      String myString = regexUtil.regexChecker("(\\d+)(?= charge)", skin);
      if (!myString.isEmpty()) {
         powerLevel = Integer.valueOf(myString);
         powerLevel = ((powerLevel / 10)) * 10;
      }
      // charge change
      if (skin.equals("fast")) {
         fastCharging = true;
         lc = true;

      } else if (skin.equals("slow")) {
         slowCharging = true;
         lc = false;

      } else if (skin.equals("unplugged")) {
         slowCharging = false;
         fastCharging = false;
      }
      if (fastCharging && !wasCharging) {
         sufficiantPowerPlugged();
         lastMeal = "i am fast charging for " + mealType();
         wasCharging = fastCharging || slowCharging;
         return;
      } // plugged
      else if (!fastCharging && wasCharging && lc) {
         sufficiantPowerUnPlugged();
         lastMeal = "i have had fast charge for " + mealType();
         wasCharging = fastCharging || slowCharging;
         return;
      } // unplugged
      if (slowCharging && !wasCharging) {
         sufficiantPowerPluggedSlow();
         lastMeal = "i am eating slow charge for " + mealType();
         wasCharging = fastCharging || slowCharging;
         return;
      } // plugged
      else if (!slowCharging && wasCharging && !lc) {
         sufficiantPowerUnPluggedSlow();
         lastMeal = "just some slow charge for " + mealType();
         wasCharging = fastCharging || slowCharging;
         return;
      } // unplugged
      wasCharging = fastCharging || slowCharging;
      // are u hungry
      if (ear.equals("are you hungry")) {
         if (wasCharging) {
            outStr = "i am eating";
            return;
         }
         switch (powerLevel) {
         case 0:
            outStr = "shiku shiku";
            return;
         case 10:
            outStr = "yes i am starving";
            return;
         case 20:
            outStr = "yes i am so hungry";
            return;
         case 30:
            outStr = "yes please feed me";
            return;
         case 90:
         case 100:
            outStr = "power lever over 90";
            return;
         default:
            outStr = "yes please feed me";
            return;
         }
      }
      if (ear.equals("did you eat")) {
         outStr = lastMeal;
      }
      // power level change while charging
      // power level change while unplugged
      if (prevPower != powerLevel) {
         if (fastCharging || slowCharging) {
            outStr = "power level at " + powerLevel + " percent";
         } else {
            switch (powerLevel) {
            case 0:
               outStr = "shiku shiku";
               return;
            case 10:
               outStr = "i am starving";
               return;
            case 20:
               outStr = "i am so hungry";
               return;
            case 30:
               outStr = "please feed me";
               return;
            case 90:
            case 100:
               outStr = "power lever over 90";
               return;
            default:
               outStr = "power level at " + powerLevel + " percent and droping";
               break;
            }
         }
      }

   }

   @Override
   public void output(Neuron noiron) {
      if (!outStr.isEmpty()) {
         noiron.algParts.add(diSkillUtils.customizedVerbatimGorithm("di_battery", new APSay(1, outStr)));
         outStr = "";
      }
   }

   private void sufficiantPowerPlugged() {
      if (powerLevel > 80) {
         outStr = "thank you";
      } else {
         outStr = "thanks I was so hungry";
      }
   }

   private void sufficiantPowerUnPlugged() {
      if (powerLevel > 80) {
         outStr = "thanks for the meal";
      } else {
         outStr = "hey i was still eating";
      }
   }

   private void sufficiantPowerPluggedSlow() {
      if (powerLevel > 80) {
         outStr = "thank you";
      } else {
         outStr = "thanks";
      }
   }

   private void sufficiantPowerUnPluggedSlow() {
      if (powerLevel > 80) {
         outStr = "ok";
      } else {
         outStr = "i am still hungry";
      }
   }

   private String mealType() {
      switch (playGround.partOfDay()) {
      case "morning":
         return "breakfast";
      case "afternoon":
         return "lunch";
      case "evening":
         return "dinner";
      }
      return "late night snack";
   }
}

modification to the main activity or B8Tri code :

Code:
private fun batterySkin(str:String){
                        var resultStr = chii!!.doIt("",str,"")
                editText.setText("")
                mbTTS.voiceIt(resultStr)
                if (mbTTS.TTS){speakOut(resultStr)}
    }
    private val mBatInfoReceiver = object : BroadcastReceiver() {
        override fun onReceive(ctxt: Context, intent: Intent) {
       // prevBatState is a global var starts as false
            val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
            val status: Int = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
            val isCharging: Boolean = status == BatteryManager.BATTERY_STATUS_CHARGING
                    || status == BatteryManager.BATTERY_STATUS_FULL
            val chargePlug: Int = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)
            val usbCharge: Boolean = chargePlug == BatteryManager.BATTERY_PLUGGED_USB
            val acCharge: Boolean = chargePlug == BatteryManager.BATTERY_PLUGGED_AC
            val charging = usbCharge || acCharge;
            if(prevBatState xor charging){
                prevBatState=charging;
                if(usbCharge){batterySkin("slow");return;}
                if(acCharge){batterySkin("fast");return;}
                batterySkin("unplugged")
            }
            if (!b8TriTimeGate.isClosed) {
                b8TriTimeGate.close(5)
                batterySkin("$level charge")
            }
        }
    }

battery code reference :
https://www.yotamarker.com/t348-android-studio-alchemy-series-b8triutil

_________________
MB over and out emp it up
Back to top Go down
Moti Barski
super
super
Moti Barski

Posts : 568
Join date : 2011-08-02

DiB8Tri a hunger skill for the living grimoire Empty
PostSubject: Re: DiB8Tri a hunger skill for the living grimoire   DiB8Tri a hunger skill for the living grimoire EmptySun Mar 07, 2021 10:36 pm


_________________
MB over and out emp it up
Back to top Go down
 
DiB8Tri a hunger skill for the living grimoire
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Jump to: