🐦swift team fuki assemble !

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
DEXplorer test snippet :

Swift:
var ap2:T1 = T1()
let a2:Algorithm = DiSkillUtils().algBuilder(algMarker: "test_dexplorer", algParts: ap2)
cera.setAlgorithm(algorithm: a2)
let dexplorer:DExplorer = DExplorer()
dexplorer.mutate(cera: cera, failure: enumFail.fail)
print(cera.act(ear: "", skin: "", eye: ""))

T1 mutating into T2
I am a T2 object
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Python:
# A simple implementation of Priority Queue
# using Queue.
class PriorityQueue(object):
    def __init__(self):
        self.queue = []

    def __str__(self):
        return ' '.join([str(i) for i in self.queue])

    # for checking if the queue is empty
    def isEmpty(self):
        return len(self.queue) == 0

    # for inserting an element in the queue
    def insert(self, data):
        self.queue.append(data)

    # for popping an element based on Priority
    def poll(self) -> object:
        if not len(self.queue) == 0:
            result0 = self.queue[0]
            del self.queue[0]
            return result0
        return None

@collector
 

collector

闇の伝説
battle programer
LV
0
 
Swift:
struct PriorityQueue<T> {
  private var elements: [T] = []

  mutating func insert(_ value: T) {
    elements.append(value)
  }

  mutating func poll() -> T? {
    guard !elements.isEmpty else {
      return nil
    }
    return elements.removeFirst()
  }

  var head: T? {
    return elements.first
  }

  var tail: T? {
    return elements.last
  }
    func isEmpty() -> Bool {
        return elements.isEmpty
    }
}
 

owly

闇の伝説
battle programer
LV
0
 
Java:
public class Fusion {
    /*
     * fuses algorithms and sends needed algorithm to a designated cerabellum
     * cobject for activation
     */
    private Hashtable<String, Integer> AlgDurations;
    private Hashtable<String, Integer> AlgDurations2 = new Hashtable<>();
    private String emot = "";
    private PriorityQueue<Algorithm> algQueue = new PriorityQueue<Algorithm>();
    private PriorityQueue<Algorithm> dangerAlgQueue = new PriorityQueue<Algorithm>();
    private Boolean reqOverload = false; // too many requests
    private Boolean repReq = false; // chobit has already accepted this request
    private HashSet<String> represantations = new HashSet<String>();
    DExplorer dExplorer = new DExplorer();
    // private Cerabellum mainCera = new Cerabellum();
    // private Cerabellum dangerCera = new Cerabellum();
    private String[] goalsToTrack = { "", "" }; // dangerCera, mainCera
    // cerabellums :
    private Cerabellum dangerCera = new Cerabellum();
    // requip cera
    private FusionCera fusionCera;
    private Cerabellum mainCera = new Cerabellum();
    // home cera
    Cerabellum[] cera = new Cerabellum[3];
    // end cerabellums

    public Fusion(Hashtable<String, Integer> algDurations) {
        super();
        AlgDurations = algDurations;
        // fusionCera = (Cerabellum) (new FusionCera(algQueue));
        fusionCera = new FusionCera(algQueue);
        cera[0] = dangerCera;
        cera[1] = fusionCera;
        cera[2] = mainCera;
        // cera = { dangerCera, fusionCera, mainCera };
    }

    public void setAlgQueue(Neuron shinkei) {
        for (Algorithm algorithm : shinkei.negativeAlgParts) {
            if (this.dangerAlgQueue.size() < 1) {
                this.dangerAlgQueue.add(algorithm.clone());
            } else {
                break;
            }
        }
        this.repReq = false;
        for (Algorithm algorithm : shinkei.algParts) {
            updateRepresentations();
            if (this.represantations.contains(algorithm.getRepresentation())) {
                this.repReq = true;
                // System.out.println("again with this shit ?");
                continue;
            }
            if (this.algQueue.size() < 5) {
                this.algQueue.add(algorithm.clone());
            } else {
                break;
            }
        }
        this.reqOverload = this.algQueue.size() > 4 && shinkei.algParts.size() > 0;
        // empty Neuron
        shinkei.empty();
        if (!dangerCera.isActive() && !dangerAlgQueue.isEmpty()) {
            dangerCera.setAlgorithm(dangerAlgQueue.poll());
            goalsToTrack[0] = dangerCera.alg.getGoal();
            goalTrack(goalsToTrack[0]);
        }
        if (!mainCera.isActive() && !algQueue.isEmpty()) {
            mainCera.setAlgorithm(algQueue.poll());
            goalsToTrack[1] = mainCera.alg.getGoal();
            goalTrack(goalsToTrack[1]);
        }
        // fuse if, {fuse}
        // goalsToTrack[0] = goalTrackReset(goalsToTrack[0]);
        // goalsToTrack[1] = goalTrackReset(goalsToTrack[1]);
        fuze();
    }

    public Boolean getRepReq() {
        return repReq;
    }

    public Boolean getReqOverload() {
        return reqOverload;
    }

    public String act(String ear, String skin, String eye) {
        String result = "";
        for (int i = 0; i < cera.length; i++) {
            if (cera[i].isActive()) {
                result = cera[i].act(ear, skin, eye);
                dExplorer.mutate(cera[i], cera[i].getFailType());
                cera[i].advanceInAlg();
                this.emot = cera[i].getEmot();
                if (i > 1) {
                int n1 = AlgDurations2.get(cera[i].alg.getGoal());
                    AlgDurations2.put(cera[i].alg.getGoal(), n1 + 1);
                }
                break;
            }
            // else(cera notactive) try go home
        }
        return result;
    }

    public String getEmot() {
        return emot;
    }

    private void updateRepresentations() {
        this.represantations = new HashSet<String>();
        for (Algorithm algorithm : this.algQueue) {
            this.represantations.add(algorithm.getRepresentation());
        }
    }

    private void goalTrack(String goal) {
        if (!AlgDurations2.containsKey(goal)) {
            // try to load, if failed :
            AlgDurations.put(goal, 0);
            AlgDurations2.put(goal, 0);
        } else {
            AlgDurations.put(goal, AlgDurations2.get(goal));
        }
    }

    private String goalTrackReset(String goal) {
        if (!goal.equals("")) {
            AlgDurations2.put(goal, 0);
        }
        return "";
    }

    private void fuze() {
        if (mainCera.isActive() && !fusionCera.isActive()) {
            int algRunTime = AlgDurations.get(mainCera.alg.getGoal());
            algRunTime = algRunTime / 2;
            Algorithm alg1;
            String g1 = "";
            int time1 = 0;
            Iterator<Algorithm> iterator = algQueue.iterator();
            while (iterator.hasNext()) {
                alg1 = iterator.next();
                g1 = alg1.getGoal();
                goalTrack(g1);
                time1 = AlgDurations.get(g1);
                if (time1 < algRunTime) {
                    fusionCera.setAlgorithm(alg1);
                    algQueue.remove(alg1);
                    fusionCera.setAbort(time1);
                    goalTrackReset(g1);
                    break;
                }
                // System.out.println(iterator.next());
            }
        }
        // TODO
        // del those lines from setalgqueue
        // and replace with this function.
        // uncheck algQueue.remove(super.alg); at FusionCera
        goalsToTrack[0] = goalTrackReset(goalsToTrack[0]);
        goalsToTrack[1] = goalTrackReset(goalsToTrack[1]);

    }
}
 

owly

闇の伝説
battle programer
LV
0
 
the init should take in a kokoro for saving not AlgDurations
save on goalTrack (AlgDurations)

delete algDurations2

 

the living tribunal

T850
Staff member
Moderator
battle programer
LV
0
 
Save and load are handles in the goal track method
And save on algdurarion save

Probably should use the alg rep as key
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Swift:
class FusionCera:Cerabellum {
    private var abort:Int = 0
    private(set) var algQueue:PriorityQueue<Algorithm>
    init(algQueue:PriorityQueue<Algorithm>) {
        self.algQueue = algQueue
    }
    func setAbort(abort:Int) {
        self.abort = abort + 1
    }
    override func act(ear: String, skin: String, eye: String) -> String {
        let result:String = super.act(ear: ear, skin: skin, eye: eye)
        abort -= 1
        if abort < 1 {
            super.setActive(isActive: false)
        }else{
            if !super.isActive(){
                let rep = super.alg!.getRepresentation()
                for i in 1..<algQueue.size() {
                    if rep == algQueue.elements[i].getRepresentation(){
                        algQueue.elements.remove(at: i); break
                    }
                }
            }
        }
        return result
    }
}
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Swift:
class Fusion {
    /*
     * fuses algorithms and sends needed algorithm to a designated cerabellum
     * cobject for activation
     */
    private var algDurations:[String:Int] = [:]
    private var emot:String = ""
    private var algQueue:PriorityQueue<Algorithm> = PriorityQueue<Algorithm>()
    private var dangerAlgQueue:PriorityQueue<Algorithm> = PriorityQueue<Algorithm>()
    private var reqOverLoad:Bool = false // too many requests
    private var repReq:Bool = false // chobit has already accepted this request
    private var represantations:Set<String> = Set<String>()
    private let dExplorer:DExplorer = DExplorer()
    private var goalsToTrack : [String] = ["",""] // // dangerCera, mainCera string array
    // cerabellums :
    private let dangerCera:Cerabellum = Cerabellum()
    // requip cera
    private(set) var fusionCera : FusionCera
    private let mainCera:Cerabellum = Cerabellum()
    private(set) var cera:[Cerabellum]
    private(set) var kokoro:Kokoro
    init(kokoro:Kokoro) {
        fusionCera = FusionCera(algQueue: self.algQueue)
        cera = [dangerCera,fusionCera,mainCera]
        self.kokoro = kokoro
    }
    func setAlgQueue(shinkei:Neuron) {
        for algorithm:Algorithm in shinkei.negativeAlgParts {
            if self.dangerAlgQueue.isEmpty(){
                self.dangerAlgQueue.elements.append(algorithm.clone())
            }else{break}
        }
        self.repReq = false
        for algorithm:Algorithm in shinkei.algParts{
            updateRepresentations()
            if self.represantations.contains(algorithm.getRepresentation()){
                self.repReq = true
                continue
            }
            if self.algQueue.size() < 5 {
                self.algQueue.insert(algorithm.clone())
            }else{
                break
            }
        }
        self.reqOverLoad = self.algQueue.size() > 4 && !shinkei.algParts.isEmpty
        // empty neuron
        shinkei.empty()
        if !dangerCera.isActive() && !dangerAlgQueue.isEmpty(){
            mainCera.setAlgorithm(algorithm: dangerAlgQueue.poll()!)
            goalsToTrack[0] = dangerCera.alg!.getRepresentation()
            goalTrack(algRepresantation: goalsToTrack[0])
        }
        if !mainCera.isActive() && !algQueue.isEmpty(){
            mainCera.setAlgorithm(algorithm: algQueue.poll()!)
            goalsToTrack[1] = mainCera.alg!.getRepresentation()
            goalTrack(algRepresantation: goalsToTrack[0])
        }
        fuze()
    }
    func getRepReq() -> Bool {
        // was a request repeatedly asked for ?
        return self.repReq
    }
    func getReqOverload() -> Bool {
        // too many requests ?
        return self.reqOverLoad
    }
    func getEmot() -> String {
        // get active AlgPart representing the emotion
        return self.emot
    }
    private func goalTrack(algRepresantation:String) {
        // make sure algDurations has this alg
        if algDurations[algRepresantation] == nil {
            let value = kokoro.grimoireMemento.simpleLoad(key: "\(algRepresantation)dur")
            let intVal = Int(value) ?? 0
            algDurations[algRepresantation] = intVal
        }
    }
    private func updateRepresentations() {
        self.represantations = Set<String>()
        for algorithm:Algorithm in self.algQueue.elements {
            self.represantations.insert(algorithm.getRepresentation())
        }
    }
    private func goalTrackReset(algRepresantation:String) {
        if !algRepresantation.isEmpty {
            algDurations[algRepresantation] = 0
        }
    }
    func fuze() {
        if mainCera.isActive() && !fusionCera.isActive(){
            var algRunTime:Int = algDurations[mainCera.alg!.getRepresentation()]!
            algRunTime = algRunTime / 2
            var gRep1:String = ""; var time1:Int = 0
            for alg1:Algorithm in algQueue.elements{
                gRep1 = alg1.getRepresentation()
                goalTrack(algRepresantation: gRep1)
                time1 = algDurations[gRep1]!
                if time1 < algRunTime {
                    fusionCera.setAlgorithm(algorithm: alg1)
                    removeAlg(represantation: gRep1)
                    fusionCera.setAbort(abort: time1)
                    goalTrackReset(algRepresantation: gRep1)
                    break
                }
            }
        }
        goalTrackReset(algRepresantation: goalsToTrack[0]);goalsToTrack[0] = ""
        goalTrackReset(algRepresantation: goalsToTrack[1]);goalsToTrack[1] = ""
    }
    func removeAlg(represantation:String) {
        for i in 1..<algQueue.size() {
            if represantation == algQueue.elements[i].getRepresentation(){
                algQueue.elements.remove(at: i); break
            }
        }
    }
    func act(ear:String, skin:String, eye:String) -> String {
        var result:String = ""
        for i in 0..<cera.count {
            if cera[i].isActive(){
                result = cera[i].act(ear: ear, skin: skin, eye: eye)
                dExplorer.mutate(cera: cera[i], failure: cera[i].getFailType())
                cera[i].advanceInAlg()
                self.emot = cera[i].emot
                if i > 1 {
                    let temp:String = cera[i].alg!.getRepresentation()
                    let n1:Int = algDurations[temp]!
                    algDurations[temp] = n1 + 1
                    kokoro.grimoireMemento.simpleSave(key: "\(temp)dur", value: "\(n1 + 1)")
                }
            }
        }
        return result
    }
}
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Swift:
class Fusion {
    /*
     * fuses algorithms and sends needed algorithm to a designated cerabellum
     * cobject for activation
     */
    private var algDurations:[String:Int] // run duration of alg, think cycles #
    private var algDurations2:[String:Int] = [:]
    private var emot:String = "" // emotion represented by the active alg part (Mutatable)
    private var algQueue:PriorityQueue<Algorithm> = PriorityQueue<Algorithm>() // regular algs in stand by to run
    private var dangerAlgQueue:PriorityQueue<Algorithm> = PriorityQueue<Algorithm>() // fight or flight algorithm in stand by to run
    private var reqOverLoad:Bool = false // too many requests
    private var repReq:Bool = false // chobit has already accepted this request
    private var represantations:Set<String> = Set<String>() // algs representation attribute
    private let dExplorer:DExplorer = DExplorer()
    private var goalsToTrack : [String] = ["",""] // // dangerCera, mainCera string array
    // cerabellums :
    private let dangerCera:Cerabellum = Cerabellum()
    // requip ceras
    private(set) var fusionCera : FusionCera
    private let mainCera:Cerabellum = Cerabellum()
    private(set) var cera:[Cerabellum]
    init(algDurations:[String:Int]) {
        fusionCera = FusionCera(algQueue: self.algQueue)
        cera = [dangerCera,fusionCera,mainCera]
        self.algDurations = algDurations
    }
    func setAlgQueue(shinkei:Neuron) {
        for algorithm:Algorithm in shinkei.negativeAlgParts {
            if self.dangerAlgQueue.isEmpty(){
                self.dangerAlgQueue.elements.append(algorithm.clone())
            }else{break}
        }
        self.repReq = false
        for algorithm:Algorithm in shinkei.algParts{
            updateRepresentations() // update all standby algs list (to hashset)
            if self.represantations.contains(algorithm.getRepresentation()){
                // this requested alg is already in stand by, this is negging !
                self.repReq = true
                continue
            }
            if self.algQueue.size() < 5 {
                // add alg if there is room in the alg queue
                self.algQueue.insert(algorithm.clone())
            }else{
                break
            }
        }
        // full of algs to do and another one is requested ? that is an overload
        self.reqOverLoad = self.algQueue.size() > 4 && !shinkei.algParts.isEmpty
        // empty neuron
        shinkei.empty()
        if !dangerCera.isActive() && !dangerAlgQueue.isEmpty(){
            dangerCera.setAlgorithm(algorithm: dangerAlgQueue.poll()!)
            goalsToTrack[0] = dangerCera.alg!.getRepresentation()
            goalTrack(algRepresantation: goalsToTrack[0])
        }
        if !mainCera.isActive() && !algQueue.isEmpty(){
            mainCera.setAlgorithm(algorithm: algQueue.poll()!)
            goalsToTrack[1] = mainCera.alg!.getRepresentation()
            goalTrack(algRepresantation: goalsToTrack[1])
        }
        fuze()
    }
    func getRepReq() -> Bool {
        // was a request repeatedly asked for ?
        return self.repReq
    }
    func getReqOverload() -> Bool {
        // too many requests ?
        return self.reqOverLoad
    }
    func getEmot() -> String {
        // get active AlgPart representing the emotion
        return self.emot
    }
    private func goalTrack(algRepresantation:String) {
        // make sure algDurations has this alg
        if algDurations2[algRepresantation] == nil {
            algDurations[algRepresantation] = 0
            algDurations2[algRepresantation] = 0
        }else{
            algDurations[algRepresantation] = algDurations2[algRepresantation]
        }
    }
    private func updateRepresentations() {
        self.represantations = Set<String>()
        for algorithm:Algorithm in self.algQueue.elements {
            self.represantations.insert(algorithm.getRepresentation())
        }
    }
    private func goalTrackReset(algRepresantation:String) {
        if !algRepresantation.isEmpty {
            algDurations2[algRepresantation] = 0
        }
    }
    private func fuze() {
        if mainCera.isActive() && !fusionCera.isActive(){
            var algRunTime:Int = algDurations[mainCera.alg!.getRepresentation()]!
            algRunTime = algRunTime / 2
            var gRep1:String = ""; var time1:Int = 0
            for alg1:Algorithm in algQueue.elements{
                gRep1 = alg1.getRepresentation()
                goalTrack(algRepresantation: gRep1)
                time1 = algDurations[gRep1]!
                // alg in queue is faster than the one running ?
                if time1 < algRunTime {
                    fusionCera.setAlgorithm(algorithm: alg1)
                    removeAlg(represantation: gRep1) // remove alg from queue, its gonna be running on the fusionCera
                    fusionCera.setAbort(abort: time1)
                    goalTrackReset(algRepresantation: gRep1)
                    break
                }
            }
        }
        goalTrackReset(algRepresantation: goalsToTrack[0]);goalsToTrack[0] = ""
        goalTrackReset(algRepresantation: goalsToTrack[1]);goalsToTrack[1] = ""
    }
    private func removeAlg(represantation:String) {
        for i in 0..<algQueue.size() {
            if represantation == algQueue.elements[i].getRepresentation(){
                algQueue.elements.remove(at: i); break
            }
        }
    }
    func act(ear:String, skin:String, eye:String) -> String {
        var result:String = ""
        for i in 0..<cera.count {
            if cera[i].isActive(){
                result = cera[i].act(ear: ear, skin: skin, eye: eye)
                dExplorer.mutate(cera: cera[i], failure: cera[i].getFailType())
                cera[i].advanceInAlg()
                self.emot = cera[i].emot
                if i > 1 {
                    let temp:String = cera[i].alg!.getRepresentation()
                    let n1:Int = algDurations2[temp]!
                    algDurations2[temp] = n1 + 1
                }
                break
            }
        }
        return result
    }
}
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Swift:
class Algorithm{
    private var goal:String = ""
    private var representation:String = ""
    var algParts: Array<Mutatable> = [Mutatable]()
    init(goal:String, representation:String, algParts: Array<Mutatable>) {
        self.goal = goal.isEmpty ? "unknown" : goal
        self.representation = representation.isEmpty ? "unknown" : representation
        self.algParts = algParts
    }
    func getGoal()->String{
        return self.goal
    }
    func getRepresentation()->String{
        return self.getRepresentation()
    }
    func getSize() -> Int {
        return algParts.count
    }
    func clone()->Algorithm{
        var deepCopy: Array<Mutatable> = [Mutatable]()
        for item in self.algParts{
            deepCopy.append(item)
        }
        return Algorithm(goal: goal, representation: representation, algParts: deepCopy)
    }
}
class CldBool{
    private var modeActive:Bool = false
    func getModeActive()->Bool{
        return self.modeActive
    }
    func setModeActive(modeActive:Bool){
        self.modeActive = modeActive
    }
}
 

owly

闇の伝説
battle programer
LV
0
 
ok team we have 5 classes to go
not including unit testing, but yeah, we are doing something very meaningful
we are getting a look into what thinking and existence is. what life is and what death is

we are gamesharking reality itself, weather NPCs recognize it or not

go team fuki ! megazordmaxing !

 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
ok team we have 5 classes to go
not including unit testing, but yeah, we are doing something very meaningful
we are getting a look into what thinking and existence is. what life is and what death is

we are gamesharking reality itself, weather NPCs recognize it or not

go team fuki ! megazordmaxing !

go suck a lemon
 

owly

闇の伝説
battle programer
LV
0
 
Java:
public class PersonalityLight {
    /*
     * this class is used in the ChobitV2 c'tor. it enables loading a complete skill
     * set (a sub class of the personality class) using 1 line of code. of course
     * you can also select specific skills to add from the subclasses c'tor. see
     * also Personality1 for example.
     */
    protected Kokoro kokoro; // soul
    protected ArrayList<AbsCmdReq> dClassesLv1 = new ArrayList<>();// can engage with anyone
    protected Hashtable<String, Integer> AlgDurations = new Hashtable<>();
    protected Fusion fusion = new Fusion(AlgDurations);

    // fusion.getReqOverload() // an overload of requests on the brain
    // fusion.getRepReq() // someone is negging and asking the same thing over and
    // over again
    /*
     * flight or fight skills may need access to the above fusion class booleans on
     * the output methode of a skill this skills will load algorithms to the highest
     * priority of the noiron which carries algorithms :
     * noiron.negativeAlgParts.add(Algorithm)
     */
    public PersonalityLight(AbsDictionaryDB absDictionaryDB) {
        this.kokoro = new Kokoro(absDictionaryDB);
    }

    public PersonalityLight() {
        this.kokoro = new Kokoro(new AbsDictionaryDBShadow());
    }

    public ArrayList<AbsCmdReq> getdClassesLv1() {
        return dClassesLv1;
    }

    public Kokoro getKokoro() {
        return kokoro;
    }

    public Hashtable<String, Integer> getAlgDurations() {
        return AlgDurations;
    }

    public Fusion getFusion() {
        return fusion;
    }
}
 
Top