👨‍💻 dev porting Auxiliary modules Java->kotlin

development

fukurou

the supreme coder
ADMIN
Kotlin:
class Cycler(var limit: Int) {
    // cycles through numbers limit to 0 non-stop
    var mode = 0
        private set

    init {
        mode = limit
    }

    fun cycleCount(): Int {
        mode--
        if (mode < 0) {
            mode = limit
        }
        return mode
    }

    fun reset() {
        mode = limit
    }

    fun setToZero() {
        mode = 0
    }

    fun sync(n: Int) {
        if (n < -1 || n > limit) {
            return
        }
        mode = n
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class Differ {
    var powerLevel = 90
        private set
    var difference = 0
        private set

    fun clearPowerLVDifference() {
        difference = 0
    }

    fun samplePowerLV(pl: Int) {
        // pl is the current power level
        difference = pl - powerLevel
        powerLevel = pl
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class InputFilter {
    // filter out non-relevant input
    // or filter in relevant data
    fun filter(ear: String, skin: String, eye: String): String {
        // override me
        return ""
    }

    fun filter(ear: String): AXKeyValuePair {
        // override me : key = context/category, value: param
        return AXKeyValuePair()
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class Magic8Ball {
    var questions = Responder()
    var answers = Responder()

    init {
        // answers :
        // Affirmative Answers
        answers.addResponse("It is certain")
        answers.addResponse("It is decidedly so")
        answers.addResponse("Without a doubt")
        answers.addResponse("Yes definitely")
        answers.addResponse("You may rely on it")
        answers.addResponse("As I see it, yes")
        answers.addResponse("Most likely")
        answers.addResponse("Outlook good")
        answers.addResponse("Yes")
        answers.addResponse("Signs point to yes")
        // Non – Committal Answers
        answers.addResponse("Reply hazy, try again")
        answers.addResponse("Ask again later")
        answers.addResponse("Better not tell you now")
        answers.addResponse("Cannot predict now")
        answers.addResponse("Concentrate and ask again")
        // Negative Answers
        answers.addResponse("Don’t count on it")
        answers.addResponse("My reply is no")
        answers.addResponse("My sources say no")
        answers.addResponse("Outlook not so good")
        answers.addResponse("Very doubtful")
        // questions :
        questions = Responder(
            "will i",
            "can i expect",
            "should i",
            "may i",
            "is it a good idea",
            "will it be a good idea for me to",
            "is it possible",
            "future hold",
            "will there be"
        )
    }

    fun engage(ear: String): Boolean {
        if (ear.isEmpty()) {
            return false
        }
        return questions.strContainsResponse(ear)
    }

    fun reply(): String {
        return answers.aResponse
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class TimeGate {
    // a gate that only stays open for x minutes after it has been set open
    // open gate returns true
    // closed state gate returns false
    // the gate starts closed
    private var pause = 5 //minutes to keep gate closed

    //private Date openedGate = addMinutesToJavaUtilDate(new Date(), pause);
    private var openedGate = Date()

    constructor(minutes: Int) : super() {
        try {
            Thread.sleep(100)
        } catch (e: InterruptedException) {
            e.printStackTrace()
        }
        pause = minutes
    }

    constructor() {
        try {
            Thread.sleep(100)
        } catch (e: InterruptedException) {
            e.printStackTrace()
        }
    }

    fun setPause(pause: Int) {
        if (pause < 60 && pause > 0) {
            this.pause = pause
        }
    }

    fun openGate() {
        // the gate will stay open for pause minutes
        openedGate = addMinutesToJavaUtilDate(Date(), pause)
    }

    fun close() {
        openedGate = Date()
    }

    val isClosed: Boolean
        get() = openedGate.before(Date())
    val isOpen: Boolean
        get() = !isClosed

    fun openGate(minutes: Int) {
        val now = Date()
        openedGate = addMinutesToJavaUtilDate(now, minutes)
    }

    private fun addMinutesToJavaUtilDate(date: Date, minutes: Int): Date {
        val calendar = Calendar.getInstance()
        calendar.time = date
        calendar.add(Calendar.MINUTE, minutes)
        return calendar.time
    }

    private fun addSecondsToJavaUtilDate(date: Date, seconds: Int): Date {
        val calendar = Calendar.getInstance()
        calendar.time = date
        calendar.add(Calendar.SECOND, seconds)
        return calendar.time
    }

    fun openGateforNSeconds(n: Int) {
        openedGate = addSecondsToJavaUtilDate(Date(), n)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class OnOffSwitch {
    private var mode = false
    private val timeGate: TimeGate = TimeGate(5)
    private var on = Responder("on", "talk to me")
    private var off = Responder("off", "stop", "shut up", "shut it", "whatever", "whateva")
    fun setPause(minutes: Int) {
        timeGate.setPause(minutes)
    }

    fun setOn(on: Responder) {
        this.on = on
    }

    fun setOff(off: Responder) {
        this.off = off
    }

    fun getMode(ear: String?): Boolean {
        if (on.responsesContainsStr(ear!!)) {
            timeGate.openGate()
            mode = true
            return true
        } else if (off.responsesContainsStr(ear)) {
            timeGate.close()
            mode = false
        }
        if (timeGate.isClosed) {
            mode = false
        }
        return mode
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
open class ElizaDeducer {
    lateinit var babble2: List<PhraseMatcher>
    fun respond(msg: String): ArrayList<AXKeyValuePair> {
        for (pm in babble2) {
            if (pm.matches(msg)) {
                return pm.respond(msg)
            }
        }
        return ArrayList()
    }

    inner class PhraseMatcher(matcher: String, val responses: List<AXKeyValuePair>) {
        val matcher: Pattern

        init {
            this.matcher = Pattern.compile(matcher)
        }

        fun matches(str: String): Boolean {
            val m = matcher.matcher(str)
            return m.matches()
        }

        fun respond(str: String): ArrayList<AXKeyValuePair> {
            val m = matcher.matcher(str)
            if (m.find()) {
            }
            val result = ArrayList<AXKeyValuePair>()
            val tmp = m.groupCount()
            for (kv in responses) {
                val tempKV = AXKeyValuePair(kv.key, kv.value)
                for (i in 0 until tmp) {
                    val s = m.group(i + 1)
                    tempKV.key = tempKV.key.replace("{$i}", s).lowercase(Locale.getDefault())
                    tempKV.value = tempKV.value.replace("{$i}", s).lowercase(Locale.getDefault())
                }
                result.add(tempKV)
            }
            return result
        }
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class ElizaDeducerInitializer : ElizaDeducer() {
    init {
        val babbleTmp = ArrayList<PhraseMatcher>()
        val kvs = ArrayList<AXKeyValuePair>()
        kvs.add(AXKeyValuePair("what is {0}", "{0} is {1}"))
        kvs.add(AXKeyValuePair("explain {0}", "{0} is {1}"))
        babbleTmp.add(PhraseMatcher("(.*) is (.*)", kvs))
        val or1 = ArrayList<AXKeyValuePair>() // simple or
        or1.add(AXKeyValuePair("{0}", "{2}"))
        or1.add(AXKeyValuePair("{1}", "{2}"))
        babbleTmp.add(PhraseMatcher("if (.*) or (.*) than (.*)", or1)) // end or1
        val if1 = ArrayList<AXKeyValuePair>() // simple if
        if1.add(AXKeyValuePair("{0}", "{1}"))
        babbleTmp.add(PhraseMatcher("if (.*) and (.*) than (.*)", if1)) // end if1
        val because1 = ArrayList<AXKeyValuePair>() // simple because
        because1.add(AXKeyValuePair("{1}", "i guess {0}"))
        babbleTmp.add(PhraseMatcher("(.*) because (.*)", because1)) // end because
        babble2 = Collections.unmodifiableList(babbleTmp)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class RailChatBot {
    private val dic = Hashtable<String, RefreshQ>()
    private var context = "default"

    init {
        dic[context] = RefreshQ()
    }

    fun setContext(context: String) {
        if (context.isEmpty()) {
            return
        }
        this.context = context
    }

    fun respondMonolog(ear: String): String {
        // monolog mode
        // recommended use of filter for the output results
        if (ear.isEmpty()) {
            return ""
        }
        if (!dic.containsKey(ear)) {
            dic[ear] = RefreshQ()
        }
        val temp: String = dic[ear]!!.rNDElement
        if (!temp.isEmpty()) {
            context = temp
        }
        return temp
    }

    fun learn(ear: String) {
        // use per each think cycle
        if (ear.isEmpty()) {
            return
        }
        if (!dic.containsKey(ear)) {
            dic[ear] = RefreshQ()
            dic[context]!!.add(ear)
            context = ear
            return
        }
        dic[context]!!.add(ear)
        context = ear
    }

    fun learnKeyValue(context: String, reply: String) {
        // learn questions and answers/ key values
        if (!dic.containsKey(context)) {
            dic[context] = RefreshQ()
        }
        if (!dic.containsKey(reply)) {
            dic[reply] = RefreshQ()
        }
        dic[context]!!.add(reply)
    }

    fun feedKeyValuePairs(kvList: ArrayList<AXKeyValuePair>) {
        if (kvList.isEmpty()) {
            return
        }
        for (kv in kvList) {
            learnKeyValue(kv.key, kv.value)
        }
    }

    fun monolog(): String {
        // succession of outputs without input involved
        return respondMonolog(context)
    }

    fun respondDialog(ear: String): String {
        // dialog mode
        // recommended use of filter for the output results
        if (ear.isEmpty()) {
            return ""
        }
        if (!dic.containsKey(ear)) {
            dic[ear] = RefreshQ()
        }
        //        if (!temp.isEmpty()){context = temp;}
        return dic[ear]!!.rNDElement
    }

    fun learnV2(ear: String, elizaDeducer: ElizaDeducer) {
        feedKeyValuePairs(elizaDeducer.respond(ear))
        learn(ear)
    }
}
 

fukurou

the supreme coder
ADMIN
ppl don't think fappin' is a time waste. they are too uncultured to understand how better quality codes are produced on empty balls.
I just jizzed and I'm sleepy
 

fukurou

the supreme coder
ADMIN
Kotlin:
class AlgorithmV2(priority: Int, alg: Algorithm) {
    private var priority = 4
    private var alg: Algorithm? = null

    init {
        this.priority = priority
        this.alg = alg
    }

    fun getAlg(): Algorithm? {
        return alg
    }

    fun setAlg(alg: Algorithm?) {
        this.alg = alg
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class SkillHubAlgDispenser(vararg skillsParams: DiSkillV2) {
    //     super class to output an algorithm out of a selection of skills
    //      engage the hub with dispenseAlg and return the value to outAlg attribute
    //      of the containing skill (which houses the skill hub)
    //      this module enables using a selection of 1 skill for triggers instead of having the triggers engage on multible skill
    //       the methode is ideal for learnability and behavioral modifications
    //       use a learnability auxiliary module as a condition to run an active skill shuffle or change methode
    //       (rndAlg , cycleAlg)
    //       moods can be used for specific cases to change behavior of the AGI, for example low energy state
    //       for that use (moodAlg)
    private val skills: ArrayList<DiSkillV2> = ArrayList<DiSkillV2>()
    private var activeSkill = 0
    private val tempN: Neuron = Neuron()
    private val rand = Random()
    private var kokoro: Kokoro = Kokoro(AbsDictionaryDB())

    init {
        for (skill in skillsParams) {
            skill.kokoro = kokoro
            skills.add(skill)
        }
    }

    fun setKokoro(kokoro: Kokoro) {
        this.kokoro = kokoro
        for (skill in skills) {
            skill.kokoro = kokoro
        }
    }

    fun addSkill(skill: DiSkillV2): SkillHubAlgDispenser {
        // builder pattern
        skill.kokoro = kokoro
        skills.add(skill)
        return this
    }

    fun dispenseAlgorithm(ear: String, skin: String, eye: String): AlgorithmV2? {
        // return value to outAlg param of (external) summoner DiskillV2
        skills[activeSkill].input(ear, skin, eye)
        skills[activeSkill].output(tempN)
        for (i in 1..5) {
            val temp: Algorithm? = tempN.getAlg(i)
            if (temp != null) {
                return AlgorithmV2(i, temp)
            }
        }
        return null
    }

    fun randomizeActiveSkill() {
        activeSkill = rand.nextInt(skills.size)
    }

    fun setActiveSkillWithMood(mood: Int) {
        // mood integer represents active skill
        // different mood = different behavior
        if (mood > -1 && mood < skills.size) {
            activeSkill = mood
        }
    }

    fun cycleActiveSkill() {
        // changes active skill
        // I recommend this method be triggered with a Learnability or SpiderSense object
        activeSkill++
        if (activeSkill == skills.size) {
            activeSkill = 0
        }
    }

    val size: Int
        get() = skills.size
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class SpiderSense {
    // enables event prediction
    private var spiderSense = false
    private val events = UniqueItemSizeLimitedPriorityQueue()
    private val alerts = UniqueItemSizeLimitedPriorityQueue()
    private var prev = ""
    fun addEvent(event: String): SpiderSense {
        // builder pattern
        events.add(event)
        return this
    }

    // input param  can be run through an input filter prior to this function
    // weather related data (sky state) only for example for weather events predictions
    fun learn(in1: String) {
        // simple prediction of an event from the events que :
        if (alerts.contains(in1)) {
            spiderSense = true
            return
        }
        // event has occured, remember what lead to it
        if (events.contains(in1)) {
            alerts.add(prev)
            return
        }
        // nothing happend
        prev = in1
    }

    fun getSpiderSense(): Boolean {
        // spider sense is tingling? event predicted?
        val temp = spiderSense
        spiderSense = false
        return temp
    }

    val alertsShallowCopy: ArrayList<String>
        get() =// return shallow copy of alerts list
            alerts.elements
    val alertsClone: ArrayList<String>
        get() {
            // return deep copy of alerts list
            val dc = DeepCopier()
            return dc.copyList(alerts.elements)
        }

    fun clearAlerts() {
        // this can for example prevent war, because say once a month or a year you stop
        // being on alert against a rival
        alerts.clear()
    } // side note:
    // use separate spider sense for data learned by hear say in contrast to actual experience
    // as well as lies (false predictions)
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class TimeAccumulator(tick: Int) {
    // accumulator ++ each tick minutes interval
    private var timeGate = TimeGate(5)
    var accumulator = 0
        private set

    fun setTick(tick: Int) {
        timeGate.setPause(tick)
    }

    init {
        // accumulation ticker
        timeGate = TimeGate(tick)
        timeGate.openGate()
    }

    fun tick() {
        if (timeGate.isClosed) {
            timeGate.openGate()
            accumulator++
        }
    }

    fun reset() {
        accumulator = 0
    }

    fun decAccumulator() {
        if (accumulator > 0) {
            accumulator--
        }
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class TODOListManager(todoLim: Int) {
    /* manages to do tasks.
    q1 tasks are mentioned once, and forgotten
    backup tasks are the memory of recently mentioned tasks
    * */
    private val q1 = UniqueItemSizeLimitedPriorityQueue()
    private val backup = UniqueItemSizeLimitedPriorityQueue()

    init {
        q1.limit = todoLim
        backup.limit = todoLim
    }

    fun addTask(e1: String?) {
        q1.add(e1!!)
    }

    val task: String
        get() {
            val temp = q1.poll()
            if (!temp.isEmpty()) {
                backup.add(temp)
            }
            return temp
        }
    val oldTask: String
        get() =// task graveyard (tasks you've tackled already)
            backup.rNDElement

    fun clearAllTasks() {
        q1.clear()
        backup.clear()
    }

    fun clearTask(task: String) {
        q1.removeItem(task)
        backup.removeItem(task)
    }

    fun containsTask(task: String): Boolean {
        return backup.contains(task)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class TrgArgue {
    var commands = UniqueItemSizeLimitedPriorityQueue()
    var contextCommands = UniqueItemSizeLimitedPriorityQueue()
    private var trgTolerance = false

    // (breaking point of argument can be established (argue till counter == N))
    var counter = 0 // count argues/requests made in succession
        private set

    fun engageCommand(s1: String): Int {
        // 0-> no engagement
        // 1-> engaged boolean gate (request made)
        // 2-> engaged argument : consecutive request made (request in succession after a previous request)
        if (s1.isEmpty()) {
            return 0
        }
        if (contextCommands.contains(s1)) {
            if (trgTolerance) {
                counter++
            }
            trgTolerance = true
            return 1
        }
        return if (trgTolerance) {
            if (!commands.strContainsResponse(s1)) {
                trgTolerance = false
                counter = 0
                0
            } else {
                counter++
                2
            }
        } else 0
    }

    fun disable() {
        // context commands are disabled till next engagement with a command
        trgTolerance = false
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class TrgEveryNMinutes(
    startTime: String, // trigger returns true every minutes interval, post start time
    private var minutes // minute interval between triggerings
    : Int
) : TrGEV3() {
    private val pl = PlayGround()
    private val trgTime: TrgTime
    private var timeStamp = ""

    init {
        timeStamp = startTime
        trgTime = TrgTime()
        trgTime.setTime(startTime)
    }

    fun setMinutes(minutes: Int) {
        if (minutes > -1) {
            this.minutes = minutes
        }
    }

    override fun trigger(): Boolean {
        if (trgTime.alarm()) {
            timeStamp = pl.getFutureInXMin(minutes)
            trgTime.setTime(timeStamp)
            return true
        }
        return false
    }

    override fun reset() {
        timeStamp = pl.currentTimeStamp
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class TrgMinute : TrGEV3 {
    // trigger true at minute once per hour
    private var hour1 = -1
    var minute: Int
    private val pl = PlayGround()

    constructor() {
        val rand = Random()
        minute = rand.nextInt(60)
    }

    constructor(minute: Int) {
        this.minute = minute
    }

    override fun trigger(): Boolean {
        val tempHour: Int = pl.hoursAsInt
        if (tempHour != hour1) {
            if (pl.minutesAsInt == minute) {
                hour1 = tempHour
                return true
            }
        }
        return false
    }

    override fun reset() {
        hour1 = -1
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class TrgSnooze( //2 recomended
    private var maxrepeats: Int
) : TrGEV3() {
    // this boolean gate will return true per minute interval
    // max repeats times.
    private var repeats = 0
    private var snooze = true
    private var snoozeInterval = 5
    private val playGround = PlayGround()
    fun setSnoozeInterval(snoozeInterval: Int) {
        if (snoozeInterval > 1 && snoozeInterval < 11) {
            this.snoozeInterval = snoozeInterval
        }
    }

    fun setMaxrepeats(maxrepeats: Int) {
        this.maxrepeats = maxrepeats
        reset()
    }

    override fun reset() {
        // refill trigger
        // engage this code when an alarm clock was engaged to enable snoozing
        repeats = maxrepeats
    }

    override fun trigger(): Boolean {
        // trigger a snooze alarm?
        val minutes: Int = playGround.minutesAsInt
        if (minutes % snoozeInterval != 0) {
            snooze = true
            return false
        }
        if (repeats > 0 && snooze) {
            snooze = false
            repeats--
            return true
        }
        return false
    }

    fun disable() {
        // engage this method to stop the snoozing
        repeats = 0
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class AXContextCmd {
    // engage on commands
    // when commands are engaged, context commans can also engage
    var commands = UniqueItemSizeLimitedPriorityQueue()
    var contextCommands = UniqueItemSizeLimitedPriorityQueue()
    var trgTolerance = false
    fun engageCommand(s1: String): Boolean {
        if (s1.isEmpty()) {
            return false
        }
        if (contextCommands.contains(s1)) {
            trgTolerance = true
            return true
        }
        if (trgTolerance && !commands.contains(s1)) {
            trgTolerance = false
            return false
        }
        return trgTolerance
    }

    fun disable() {
        // context commands are disabled till next engagement with a command
        trgTolerance = false
    }
}
 
Top