👨‍💻 dev Java->Kotlin port

development

owly

闇の伝説
Staff member
戦闘 コーダー
project progress at 100%
 
0% 100%

1. AbsDictionaryDB +
2. Mutatable +
3. APSay:Mutatable +
4. DeepCopier +
5. APVerbatim:Mutatable +
6. GrimoireMemento +
7. Algorithm +
8. CldBool +
9. APCldVerbatim:APVerbatim +
10. Kokoro +
11. Neuron +
12. DiSkillUtils +
13. DiSkillV2 +
14. DiHelloWorld:DiSkillV2 +
15. Cerabellum +
16. Fusion +
17. Thinkable +
18. Chobits:Thinkable +
19. Brain +
20. DiSysOut +
@fukurou
 
Last edited:

fukurou

the supreme coder
ADMIN
Kotlin:
class AbsDictionaryDB {
    fun save(key: String?, value: String?) {
        // save to DB (override me)
    }

    fun load(key: String?): String {
        // override me
        return "null"
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
open class Mutatable {
// one part of an algorithm, it is a basic simple action or sub goal
    var algKillSwitch = false
    open fun action(ear: String, skin: String, eye: String): String {return  ""}
open fun completed(): Boolean {return false}
open fun clone(): Mutatable {return Mutatable()}
fun myName(): String {
// Returns the class name
        return this.javaClass.simpleName
    }
}
 
Last edited:

fukurou

the supreme coder
ADMIN
Kotlin:
/* it speaks something x times
 * a most basic skill.
 * also fun to make the chobit say what you want
 * */
class APSay(repetitions: Int, param: String) : Mutatable() {
    protected var param: String
    private var at: Int

    init {
        at = if (repetitions > 10) 10 else repetitions
        this.param = param
    }

    override fun action(ear: String, skin: String, eye: String): String {
        var axnStr = ""
        if (at > 0) {
            if (!ear.equals(param, ignoreCase = true)) {
                axnStr = param
                at--
            }
        }
        return axnStr
    }

    override fun completed(): Boolean {
        return at < 1
    }

    override fun clone(): Mutatable {
        return APSay(at, param)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class DeepCopier {
    fun copyList(original: ArrayList<String>?): ArrayList<String> {
        return ArrayList(original)
    }

    fun copyListOfInts(original: ArrayList<Int>?): ArrayList<Int> {
        return ArrayList(original)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class APVerbatim : Mutatable {
    /*
     * this algorithm part says each past param verbatim
     */
    private var sentences = ArrayList<String>()
    private var at = 0

    constructor(vararg sentences: String) {
        for (i in sentences.indices) {
            this.sentences.add(sentences[i])
        }
        if (0 == sentences.size) {
            at = 30
        }
    }

    constructor(list1: ArrayList<String>) {
        sentences = ArrayList(list1)
        if (0 == sentences.size) {
            at = 30
        }
    }

    override fun action(ear: String, skin: String, eye: String): String {
        // TODO Auto-generated method stub
        var axnStr = ""
        if (at < sentences.size) {
            axnStr = sentences[at]
            at++
        }
        return axnStr
    }

    override fun completed(): Boolean {
        return at >= sentences.size
    }

    override fun clone(): Mutatable {
        return APVerbatim(sentences)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
public class GrimoireMemento {
    private AbsDictionaryDB absDictionaryDB;

    public GrimoireMemento(AbsDictionaryDB absDictionaryDB) {
        super();
        this.absDictionaryDB = absDictionaryDB;
    }
    public String simpleLoad(String key){
        return this.absDictionaryDB.load(key);
    }
    public void simpleSave(String key, String value){
        if(key.startsWith("AP")||key.isEmpty()||value.isEmpty()){return;}
        this.absDictionaryDB.save(key,value);
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
// a step-by-step plan to achieve a goal
class Algorithm(algParts: ArrayList<Mutatable>) {
    var algParts = ArrayList<Mutatable>()

    init {
        this.algParts = algParts
    }

    val size: Int
        get() = algParts.size

    fun clone(): Algorithm {
        // returns a deep copy algorithm
        val parts = ArrayList<Mutatable>()
        for (absAlgPart in algParts) {
            parts.add(absAlgPart.clone())
        }
        return Algorithm(parts)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class CldBool {
    //cloudian : this class is used to provide shadow reference to a boolean variable
    var modeActive = false
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class APCldVerbatim : Mutatable {
    /*
     * this algorithm part says each past param verbatim
     */
    private var sentences = ArrayList<String>()
    private var at = 0
    private var cldBool // access via shallow reference
            : CldBool

    constructor(cldBool: CldBool, vararg sentences: String) {
        for (i in sentences.indices) {
            this.sentences.add(sentences[i])
        }
        if (0 == sentences.size) {
            at = 30
        }
        this.cldBool = cldBool
        this.cldBool.modeActive = true
    }

    constructor(cldBool: CldBool, list1: ArrayList<String>) {
        sentences = ArrayList(list1)
        if (0 == sentences.size) {
            at = 30
        }
        this.cldBool = cldBool
        this.cldBool.modeActive = true
    }

    override fun action(ear: String, skin: String, eye: String): String {
        var axnStr = ""
        if (at < sentences.size) {
            axnStr = sentences[at]
            at++
        }
        cldBool.modeActive = at < sentences.size
        return axnStr
    }

    override fun completed(): Boolean {
        return at >= sentences.size
    }

    override fun clone(): Mutatable {
        return APCldVerbatim(cldBool, sentences)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
/* this class enables:
communication between skills
utilization of a database for skills
in skill monitoring of which Mutatable was last run by the AI (consciousness)
this class is a built-in attribute in skill objects.
* */
class Kokoro(absDictionaryDB: AbsDictionaryDB?) {
    var emot = ""
    var grimoireMemento: GrimoireMemento
    var toHeart = Hashtable<String, String>()

    init {
        grimoireMemento = GrimoireMemento(absDictionaryDB!!)
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
// used to transport algorithms to other classes
class Neuron {
    private val defcons = Hashtable<Int, ArrayList<Algorithm>>()

    init {
        for (i in 1..5) {
            defcons[i] = ArrayList()
        }
    }

    fun insertAlg(priority: Int, alg: Algorithm) {
        if (priority in 1..5) {
            if (defcons[priority]!!.size < 4) {
                defcons[priority]!!.add(alg)
            }
        }
    }

    fun getAlg(defcon: Int): Algorithm? {
        if (defcons[defcon]!!.size > 0) {
            val temp = defcons[defcon]!![0]
            defcons[defcon]!!.removeAt(0)
            return temp.clone()
        }
        return null
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class DISkillUtils {
// alg part based algorithm building methods
    // var args param
    fun algBuilder(vararg algParts: Mutatable): Algorithm {
// returns an algorithm built with the algPart varargs
        val algParts1 = ArrayList<Mutatable>()
for (i in algParts.indices) {
            algParts1.add(algParts[i])
        }
return Algorithm(algParts1)
    }

// String based algorithm building methods
    fun simpleVerbatimAlgorithm(vararg sayThis: String): Algorithm {
// returns an algorithm that says the sayThis Strings verbatim per think cycle
        return algBuilder(APVerbatim(*sayThis))
    }

// String part based algorithm building methods with cloudian (shallow ref object to inform on alg completion)
    fun simpleCloudiandVerbatimAlgorithm(cldBool: CldBool, vararg sayThis: String): Algorithm {
// returns an algorithm that says the sayThis Strings verbatim per think cycle
        return algBuilder(APCldVerbatim(cldBool, *sayThis))
    }

fun strContainsList(str1: String, items: ArrayList<String>): String {
// returns the 1st match between words in a string and values in a list.
        for (temp in items) {
if (str1.contains(temp)) {
return temp
            }
        }
return ""
    }
}
 
Last edited:

fukurou

the supreme coder
ADMIN
Kotlin:
open class DiSkillV2 {
protected var kokoro =
Kokoro(AbsDictionaryDB()) // consciousness, shallow ref class to enable interskill communications
    protected var diSkillUtils = DISkillUtils()
protected var outAlg: Algorithm? = null // skills output
    protected var outpAlgPriority = -1 // defcon 1->5

    // skill triggers and algorithmic logic
    open fun input(ear: String, skin: String, eye: String) {}

// extraction of skill algorithm to run (if there is one)
    fun output(noiron: Neuron) {
if (outAlg != null) {
noiron.insertAlg(outpAlgPriority, outAlg!!)
outpAlgPriority = -1
            outAlg = null
        }
    }

// in skill algorithm building shortcut methods:
    protected fun setVerbatimAlg(priority: Int, vararg sayThis: String) {
// build a simple output algorithm to speak string by string per think cycle
        // uses varargs param
        outAlg = diSkillUtils.simpleVerbatimAlgorithm(*sayThis)
outpAlgPriority = priority // 1->5 1 is the highest algorithm priority
    }

protected fun setSimpleAlg(vararg sayThis: String) {
// based on the setVerbatimAlg method
        // build a simple output algorithm to speak string by string per think cycle
        // uses varargs param
        outAlg = diSkillUtils.simpleVerbatimAlgorithm(*sayThis)
outpAlgPriority = 4 // 1->5 1 is the highest algorithm priority
    }

protected fun setVerbatimAlgFromList(priority: Int, sayThis: ArrayList<String>) {
// build a simple output algorithm to speak string by string per think cycle
        // uses list param
        outAlg = diSkillUtils.algBuilder(APVerbatim(sayThis))
outpAlgPriority = priority // 1->5 1 is the highest algorithm priority
    }

protected fun algPartsFusion(priority: Int, vararg algParts: Mutatable) {
// build a custom algorithm out of a chain of algorithm parts(actions)
        outAlg = diSkillUtils.algBuilder(*algParts)
outpAlgPriority = priority // 1->5 1 is the highest algorithm priority
    }

fun pendingAlgorithm(): Boolean {
// is an algorithm pending?
        return outAlg != null
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class DiHelloWorld  // hello world skill for testing purposes
    : DiSkillV2() {
    override fun input(ear: String, skin: String, eye: String) {
        when (ear) {
            "hello" -> super.setVerbatimAlg(4, "hello world") // 1->5 1 is the highest algorithm priority
        }
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class Cerabellum {
    // runs an algorithm
    private var fin = 0
    var at = 0
        private set
    private var incrementAt = false
    fun advanceInAlg() {
        if (incrementAt) {
            incrementAt = false
            at++
            if (at == fin) {
                isActive = false
            }
        }
    }

    var alg: Algorithm? = null
    var isActive = false
        private set
    var emot = ""
        private set

    fun setAlgorithm(algorithm: Algorithm): Boolean {
        if (!isActive && !algorithm.algParts.isEmpty()) {
            alg = algorithm
            at = 0
            fin = algorithm.size
            isActive = true
            emot = alg!!.algParts.get(at).myName() // updated line
            return false
        }
        return true
    }

    fun act(ear: String, skin: String, eye: String): String {
        var axnStr = ""
        if (!isActive) {
            return axnStr
        }
        if (at < fin) {
            axnStr = alg!!.algParts.get(at).action(ear, skin, eye)
            emot = alg!!.algParts.get(at).myName()
            if (alg!!.algParts.get(at).completed()) {
                incrementAt = true
            }
        }
        return axnStr
    }

    fun deActivation() {
        isActive = isActive && !alg!!.algParts.get(at).algKillSwitch
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class Fusion {
    var emot = ""
        private set
    private var result = ""
    private val ceraArr = arrayOfNulls<Cerabellum>(5)

    init {
        for (i in 0..4) {
            ceraArr[i] = Cerabellum()
        }
    }

    fun loadAlgs(neuron: Neuron) {
        for (i in 1..5) {
            if (!ceraArr[i - 1]!!.isActive) {
                val temp = neuron.getAlg(i)
                if (temp != null) {
                    ceraArr[i - 1]!!.setAlgorithm(temp)
                }
            }
        }
    }

    fun runAlgs(ear: String?, skin: String?, eye: String?): String {
        result = ""
        for (i in 0..4) {
            if (!ceraArr[i]!!.isActive) {
                continue
            }
            result = ceraArr[i]!!.act(ear!!, skin!!, eye!!)
            ceraArr[i]!!.advanceInAlg()
            emot = ceraArr[i]!!.emot
            ceraArr[i]!!.deActivation() // deactivation if Mutatable.algkillswitch = true
            return result
        }
        emot = ""
        return result
    }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
open class thinkable {
open fun think(ear: String, skin: String, eye: String): String {
// override me
        return ""
    }
}
 
Last edited:

fukurou

the supreme coder
ADMIN
Kotlin:
class Chobits : thinkable() {
    protected var dClasses = ArrayList<DiSkillV2>()
    var fusion: Fusion
        protected set
    protected var noiron: Neuron

    // use this for telepathic communication between different chobits objects
    // several chobits can use the same soul
    // this enables telepathic communications
    // between chobits in the same project
    var kokoro = Kokoro(AbsDictionaryDB()) // consciousness

    init {
        // c'tor
        fusion = Fusion()
        noiron = Neuron()
    }

    fun setDataBase(absDictionaryDB: AbsDictionaryDB?) {
        kokoro = Kokoro(absDictionaryDB)
    }

    fun addSkill(skill: DiSkillV2): Chobits {
        // add a skill (builder design patterned func))
        skill.kokoro = kokoro
        dClasses.add(skill)
        return this
    }

    fun clearSkills() {
        // remove all skills
        dClasses.clear()
    }

    fun addSkills(vararg skills: DiSkillV2) {
        for (skill in skills) {
            skill.kokoro = kokoro
            dClasses.add(skill)
        }
    }

    fun removeSkill(skill: DiSkillV2) {
        dClasses.remove(skill)
    }

    fun containsSkill(skill: DiSkillV2): Boolean {
        return dClasses.contains(skill)
    }

    fun think(ear: String?, skin: String?, eye: String?): String {
        for (dCls in dClasses) {
            inOut(dCls, ear, skin, eye)
        }
        fusion.loadAlgs(noiron)
        return fusion.runAlgs(ear, skin, eye)
    }

    val soulEmotion: String
        get() =// get the last active AlgPart name
        // the AP is an action, and it also represents
            // an emotion
            fusion.emot

    protected fun inOut(dClass: DiSkillV2, ear: String?, skin: String?, eye: String?) {
        dClass.input(ear!!, skin!!, eye!!) // new
        dClass.output(noiron)
    }

    val skillList: ArrayList<String>
        get() {
            val result = ArrayList<String>()
            for (skill in dClasses) {
                result.add(skill.javaClass.simpleName)
            }
            return result
        }
}
 

fukurou

the supreme coder
ADMIN
Kotlin:
class Chobits : thinkable() {
    protected var dClasses = ArrayList<DiSkillV2>()
    var fusion: Fusion
        protected set
    protected var noiron: Neuron

    // use this for telepathic communication between different chobits objects
    // several chobits can use the same soul
    // this enables telepathic communications
    // between chobits in the same project
    var kokoro = Kokoro(AbsDictionaryDB()) // consciousness

    init {
        // c'tor
        fusion = Fusion()
        noiron = Neuron()
    }

    fun setDataBase(absDictionaryDB: AbsDictionaryDB?) {
        kokoro = Kokoro(absDictionaryDB)
    }

    fun addSkill(skill: DiSkillV2): Chobits {
        // add a skill (builder design patterned func))
        skill.kokoro = kokoro
        dClasses.add(skill)
        return this
    }

    fun clearSkills() {
        // remove all skills
        dClasses.clear()
    }

    fun addSkills(vararg skills: DiSkillV2) {
        for (skill in skills) {
            skill.kokoro = kokoro
            dClasses.add(skill)
        }
    }

    fun removeSkill(skill: DiSkillV2) {
        dClasses.remove(skill)
    }

    fun containsSkill(skill: DiSkillV2): Boolean {
        return dClasses.contains(skill)
    }

    override fun think(ear: String, skin: String, eye: String): String {
        for (dCls in dClasses) {
            inOut(dCls, ear, skin, eye)
        }
        fusion.loadAlgs(noiron)
        return fusion.runAlgs(ear, skin, eye)
    }

    val soulEmotion: String
        get() =// get the last active AlgPart name
        // the AP is an action, and it also represents
            // an emotion
            fusion.emot

    protected fun inOut(dClass: DiSkillV2, ear: String, skin: String, eye: String) {
        dClass.input(ear, skin, eye) // new
        dClass.output(noiron)
    }

    val skillList: ArrayList<String>
        get() {
            val result = ArrayList<String>()
            for (skill in dClasses) {
                result.add(skill.javaClass.simpleName)
            }
            return result
        }
}
 
Top