🐦swift team fuki assemble !

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Swift:
/*
 it speaks something x times
 a most basic skill.
 also fun to make the chobit say what you want */
class APsay:Mutatable{
    var at:Int=10
    var param:String="hmm"
    convenience init(repetitions:Int, param:String) {
        self.init()
        if repetitions<at {self.at=repetitions}
        self.param=param
    }
    override func action(ear: String, skin: String, eye: String) -> String {
        var axnStr=""
        if self.at>0{
            if ear.lowercased() != self.param{
                axnStr=self.param
                self.at -= 1
            }
        }
        return axnStr
    }
    override func completed() -> Bool {
        return self.at < 1
    }
    override func clone() -> Mutatable {
        return APsay(repetitions: self.at, param: self.param)
    }
}
 

owly

闇の伝説
battle programer
LV
0
 
Python:
class APVerbatim(Mutatable):
    '''this algorithm part says each past param verbatim'''

    def __init__(self, *args) -> None:
        super().__init__()
        self.sentences = []
        self.at = 0

        try:
            if isinstance(args[0], list):
                self.sentences = args[0]
                if 0 == len(self.sentences):
                    self.at = 30
            else:
                for i in range(len(args)):
                    self.sentences.append(args[i])
        except:
            self.at = 30

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """TODO Auto-generated method stub"""
        axnStr = ""
        if self.at < len(self.sentences):
            axnStr = self.sentences[self.at]
            self.at += 1
        return axnStr

    # Override
    def failure(self, input: str) -> enumFail:
        """TODO Auto-generated method stub"""
        return enumFail.ok

    # Override
    def completed(self) -> bool:
        """TODO Auto-generated method stub"""
        return self.at >= len(self.sentences)

    # Override
    def clone(self) -> AbsAlgPart:
        """TODO Auto-generated method stub"""
        return APVerbatim(self.sentences)

 

owly

闇の伝説
battle programer
LV
0
 
Java:
public class APVerbatim extends AbsAlgPart {
    /*
     * this algorithm part says each past param verbatim
     */
    private ArrayList<String> sentences = new ArrayList<String>();
    private int at = 0;

    public APVerbatim(String... sentences) {
        for (int i = 0; i < sentences.length; i++) {
            this.sentences.add(sentences[i]);
        }
        if (0 == sentences.length) {
            at = 30;
        }
    }

    public APVerbatim(ArrayList<String> list1) {
        this.sentences = new ArrayList<String>(list1);
        if (0 == this.sentences.size()) {
            at = 30;
        }
    }

    @Override
    public String action(String ear, String skin, String eye) {
        // TODO Auto-generated method stub
        String axnStr = "";
        if (this.at < this.sentences.size()) {
            axnStr = this.sentences.get(at);
            at++;
        }
        return axnStr;
    }

    @Override
    public enumFail failure(String input) {
        // TODO Auto-generated method stub
        return enumFail.ok;
    }

    @Override
    public Boolean completed() {
        // TODO Auto-generated method stub
        return at >= this.sentences.size();
    }

    @Override
    public AbsAlgPart clone() {
        // TODO Auto-generated method stub
        return new APVerbatim(this.sentences);
    }

    @Override
    public Boolean itemize() {
        // TODO add logic
        // at home
        return true;
    }
}

 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
main

Swift:
    let x1 = AbsDictionaryDB()
print(x1.load(key: ""))
var fail = enumFail.ok
print(fail)
let m1 = Mutatable()
print(m1.myName())
var t1:Mutatable = T1()
print(t1.action(ear: "", skin: "", eye: ""))
print(t1.completed()) // true
t1 = t1.mutation()
print("after mutation")
print(t1.action(ear: "", skin: "", eye: ""))
print(t1.completed()) // true
//test APSay
let apSay = APsay(repetitions: 2, param: "hello fuki")
print(apSay.completed())
print(apSay.action(ear: "", skin: "", eye: ""))
print(apSay.action(ear: "", skin: "", eye: ""))
print(apSay.action(ear: "", skin: "", eye: ""))
print(apSay.completed())
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Swift:
class DeepCopier{
    func copyList(original: Array<String>)->Array<String>{
        var deepCopy: Array<String> = [String]()
        for item in original{
            deepCopy.append(item)
        }
        return deepCopy
    }
}
class APVerbatim:Mutatable{
    // this algorithm part says each past param verbatim
    var at:Int=0
    var sentences: Array<String> = [String]()
    convenience init(_ sentences:String...){
        self.init()
        for item in sentences{
            self.sentences.append(item)
        }
        if sentences.isEmpty {
            self.at = 30
        }
    }
    convenience init(sentences: Array<String>){
        self.init()
        for item in sentences{
            self.sentences.append(item)
        }
        if sentences.isEmpty {
            self.at = 30
        }
    }
    override func action(ear: String, skin: String, eye: String) -> String {
        var axnStr = ""
        if self.at < self.sentences.count{
            axnStr=self.sentences[at]
            self.at += 1
        }
        return axnStr
    }
    override func completed() -> Bool {
        return self.at == self.sentences.count
    }
    override func clone() -> Mutatable {
        let deepCoper = DeepCopier()
        return APVerbatim(sentences: deepCoper.copyList(original: sentences))
    }
}
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Java:
public class GrimoireMemento {
    private Hashtable<String, String> rootToAPNumDic = new Hashtable<>();
    private Hashtable<String, AbsAlgPart> APNumToObjDic = new Hashtable<>();
    private AbsDictionaryDB absDictionaryDB;

    public GrimoireMemento(AbsDictionaryDB absDictionaryDB) {
        super();
        this.absDictionaryDB = absDictionaryDB;
    }

    public AbsAlgPart load(AbsAlgPart obj) {
        /*
         * load final mutation from memory of obj
         */
        String objName = obj.getClass().getSimpleName();
        String objRoot = objName.replaceAll("\\d+", "");
        // if not in active DB try adding from external DB
        if (!rootToAPNumDic.containsKey(objRoot)) {
            String temp = this.absDictionaryDB.load(objRoot);
            if (this.absDictionaryDB.getExistsInDB()) {
                rootToAPNumDic.put(objRoot, temp);
            }
        }
        if (!rootToAPNumDic.containsKey(objRoot)) {
            rootToAPNumDic.put(objRoot, objName);
            return obj;
        }

        if (rootToAPNumDic.get(objRoot).equals(objName)) {
            return obj;
        } else {
            String APNum = rootToAPNumDic.get(objRoot);
            if (APNumToObjDic.containsKey(APNum)) {
                return APNumToObjDic.get(APNum).clone();
            } else {
                loadMutations(obj, objName, objRoot);
                return APNumToObjDic.get(APNum).clone();
            }
        }
    }

    public void reqquipMutation(String mutationAPName) {
        // save mutation
        rootToAPNumDic.put(mutationAPName.replaceAll("\\d+", ""), mutationAPName);
        this.absDictionaryDB.save(mutationAPName.replaceAll("\\d+", ""), mutationAPName);
    }

    private void loadMutations(AbsAlgPart obj, String objName, String objRoot) {
        // make sure all the AP mutation sets of obj are present
        // this assumes the last mutation mutates into the prime mutation
        Mutatable mutant;
        String end = objName;
        do {
            APNumToObjDic.put(obj.getClass().getSimpleName(), obj.clone());
            mutant = (Mutatable) obj;
            obj = mutant.mutation();
        }
        while (!end.equals(obj.getClass().getSimpleName()));
    }
    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);
    }
}

:nrv:
 

fukurou

the supreme coder
Staff member
Administrator
LV
0
 
Python:
class GrimoireMemento:
    def __init__(self, absDictionaryDB: AbsDictionaryDB) -> None:
        super().__init__()
        self.rootToAPNumDic = {}  # string, string
        self.APNumToObjDic = {}  # string, Mutatable
        self.absDictionaryDB = absDictionaryDB

    def load(self, obj: Mutatable) -> Mutatable:
        '''load final mutation from memory of obj'''
        objName = obj.__class__.__name__
        objRoot = re.sub(r'\d+', '', objName)
        # if not in active DB try adding from external DB
        if not self.rootToAPNumDic.keys().__contains__(objRoot):
            temp = self.absDictionaryDB.load(objRoot)
            if temp != "null":
                self.rootToAPNumDic[objRoot] = temp

        if (not self.rootToAPNumDic.keys().__contains__(objRoot)):
            self.rootToAPNumDic[objRoot] = objName
            return obj

        if (self.rootToAPNumDic[objRoot] == objName):
            # the mutatable does not have mutations
            return obj
        else:
            APNum = self.rootToAPNumDic[objRoot]
            if (self.APNumToObjDic.keys().__contains__(APNum)):
                return self.APNumToObjDic[APNum].clone()
            else:
                self.loadMutations(obj, objName, objRoot)
                return self.APNumToObjDic[APNum].clone()

    def reqquipMutation(self, mutationAPName: str):
        '''save mutation'''
        self.rootToAPNumDic[re.sub(r'\d+', '', mutationAPName)] = mutationAPName
        self.absDictionaryDB.save(re.sub(r'\d+', '', mutationAPName), mutationAPName)

    def loadMutations(self, obj: Mutatable, objName: str, objRoot: str):
        '''
        make sure all the AP mutation sets of obj are present
        self assumes the last mutation mutates into the prime mutation
        '''
        mutant = obj
        end = objName
        while (True):
            self.APNumToObjDic[obj.__class__.__name__] = obj.clone()
            mutant = obj
            obj = mutant.mutation()
            if (end == obj.__class__.__name__):
                break

    def simpleLoad(self, key: str) -> str:
        return self.absDictionaryDB.load(key)

    def simpleSave(self, key: str, value: str):
        if (key.startswith("AP") or key == "" or value == ""):
            return
        self.absDictionaryDB.save(key, value)
 
Top