java to swift 141223

owly

闇の伝説
Staff member
戦闘 コーダー
Swift:
import Foundation

class DiTreater: DiSkillV2 {
    private var handshake = AXHandshake()
    var replies = Responder(responses: ["stop arguing", "just do it", "behave", "be a big boy and do it", "bad boy no more fussing", "i know best"])
    var contextCmd = TrgArgue()
    
    func setTime(time_stamp: String) -> DiTreater {
        handshake.setTimeStamp(time_stamp: time_stamp)
        return self
    }
    
    func setDripper(percentage: Int) -> DiTreater {
        handshake.setDripperPercent(percentage: percentage)
        return self
    }
    
    init() {
        handshake.setTimeStamp(time_stamp: "19:30")
        contextCmd.contextCommands.append("do i have to wear a diaper")
        contextCmd.commands.append("but")
        contextCmd.commands.append("do not want to")
        contextCmd.commands.append("why")
        contextCmd.commands.append("no")
    }
    
    override func input(ear: String, skin: String, eye: String) {
        if handshake.engage(ear: ear) {
            contextCmd.engageCommand(ear: "do i have to wear a diaper")
            setVerbatimAlg(4, "put on your diaper sweet heart")
            return
        }
        if handshake.trigger() {
            setVerbatimAlg(4, handshake.getUser_name())
            return
        }
        switch contextCmd.engageCommand(ear: ear) {
        case 1:
            setVerbatimAlg(4, "you know you do")
        case 2:
            setVerbatimAlg(4, replies.getAResponse())
        default:
            break
        }
    }
    
    func setUser_nickname(nickname: String) -> DiTreater {
        handshake.setUser_name(nickname: nickname)
        return self
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class DiTreater: DiSkillV2 {
    private var handshake = AXHandshake()
    var replies = Responder("stop arguing", "just do it", "behave", "be a big boy and do it", "bad boy no more fussing", "i know best")
    var contextCmd = TrgArgue()
    
    func setTime(time_stamp: String) -> DiTreater {
        handshake.setTimeStamp(time_stamp)
        return self
    }
    
    func setDripper(percentage: Int) -> DiTreater {
        handshake.setDripperPercent(percentage)
        return self
    }
    
    override init() {
        handshake.setTimeStamp("19:30")
        contextCmd.contextCommands.input(in1: "do i have to wear a diaper")
        contextCmd.commands.input(in1:"but")
        contextCmd.commands.input(in1:"do not want to")
        contextCmd.commands.input(in1:"why")
        contextCmd.commands.input(in1:"no")
    }
    
    override func input(ear: String, skin: String, eye: String) {
        if handshake.engage(ear) {
            contextCmd.engageCommand(ear: "do i have to wear a diaper")
            setSimpleAlg(sayThis: "put on your diaper sweet heart")
            return
        }
        if handshake.trigger() {
            setSimpleAlg(sayThis:  handshake.getUser_name())
            return
        }
        switch contextCmd.engageCommand(ear: ear) {
        case 1:
            setSimpleAlg(sayThis:  "you know you do")
        case 2:
            setSimpleAlg(sayThis:  replies.getAResponse())
        default:
            break
        }
    }
    
    func setUser_nickname(nickname: String) -> DiTreater {
        handshake.setUser_name(nickname)
        return self
    }
}

need to add @discardableResult
 

fukurou

the supreme coder
ADMIN
Swift:
class DIBlabber: DiSkillV2 {
    private var isActive: Bool = true // skill toggler
    var skillToggler: AXContextCmd = AXContextCmd()
    // chat mode select
    var modeSwitch: AXContextCmd = AXContextCmd()
    var mode: Cycler = Cycler(limit: 1)
    // engage chatbot
    var engage: AXContextCmd = AXContextCmd()
    // chatbots
    var chatbot1: AXNPC2 = AXNPC2(replyStockLim: 30, outputChance: 90) // pal mode chat module
    var chatbot2: AXNPC2 = AXNPC2(replyStockLim: 30, outputChance: 90) // discreet mode chat module
    // auto mode
    private var autoEngage: Responder = Responder("engage automatic mode", "automatic mode", "auto mode")
    private var shutUp: Responder = Responder("stop", "shut up", "silence", "be quite", "be silent")
    private var tg: TimeGate = TimeGate(pause: 5)
    private var nPCPlus: Int = 5 // increase rate of output in self auto reply mode
    private var nPCNeg: Int = -10 // decrease rate of output in self auto reply mode
    
    init(skill_name: String) {
        skillToggler.contextCommands.input(in1: "toggle \(skill_name)")
        skillToggler.commands.input(in1: "again")
        skillToggler.commands.input(in1: "repeat")
        modeSwitch.contextCommands.input(in1: "switch \(skill_name) mode")
        modeSwitch.commands.input(in1: "again")
        modeSwitch.commands.input(in1: "repeat")
        engage.contextCommands.input(in1: "engage \(skill_name)")
        engage.commands.input(in1: "talk")
        engage.commands.input(in1: "talk to me")
        engage.commands.input(in1: "again")
        engage.commands.input(in1: "repeat")
        mode.setToZero()
    }
    
    override func input(ear: String, skin: String, eye: String) {
        // skill toggle:
        if skillToggler.engageCommand(ear: ear) {
            isActive = !isActive
        }
        if !isActive {
            return
        }
        // chat-bot mode switch mode
        if modeSwitch.engageCommand(ear: ear) {
            mode.cycleCount()
            setSimpleAlg(sayThis: talkMode())
            return
        }
        
        switch mode.getMode() {
        case 0:
            mode0(ear)
        case 1:
            mode1(ear)
        default:
            break
        }
    }
    
    private func mode0(_ ear: String) {
        if !kokoro.toHeart["diblabber", default: ""].isEmpty {
            kokoro.toHeart["diblabber"] = ""
            setSimpleAlg(sayThis: chatbot1.forceRespond())
            return
        }
        NPCUtilization(chatbot1, ear)
    }
    
    private func mode1(_ ear: String) {
        // auto engage
        if autoEngage.strContainsResponse(ear: ear) {
            tg.openGate()
            setSimpleAlg(sayThis: "auto NPC mode engaged")
            return
        }
        if shutUp.strContainsResponse(ear:ear) {
            tg.closeGate()
            setSimpleAlg(sayThis:  "auto NPC mode disengaged")
            return
        }
        if tg.isOpen() {
            var plus = nPCNeg
            if !ear.isEmpty {
                plus = nPCPlus
            }
            let result = chatbot2.respondPlus(plus: plus)
            if !result.isEmpty {
                setSimpleAlg(sayThis: result)
                return
            }
        }
        // end auto engage code snippet
        NPCUtilization(chatbot2, ear)
    }
    
    private func talkMode() -> String {
        switch mode.getMode() {
        case 0:
            return "friend mode"
        case 1:
            return "discreet mode"
        default:
            return "mode switched"
        }
    }
    // auto mode setters
    func setNPCTimeSpan(_ n: Int) {
        tg.setPause(pause: n)
    }
    
    func setNPCNeg(_ n: Int) {
        // lower NPC auto output chance
        nPCNeg = n
    }
    
    func setNPCPlus(_ n: Int) {
        // increase NPC auto output chance
        nPCPlus = n
    }
    // chat module common tasks
    private func NPCUtilization(_ npc: AXNPC2, _ ear: String) {
        var result = ""
        // engage
        if engage.engageCommand(ear: ear) {
            result = npc.respond()
            if !result.isEmpty {
                setSimpleAlg(sayThis: result)
                return
            }
        }
        // str engage
        result = npc.strRespond(ear: ear)
        if !result.isEmpty {
            setSimpleAlg(sayThis: result)
        }
        // forced learn (say n)
        if !npc.learn(ear: ear) {
            // strlearn
            npc.strLearn(ear: ear)
        }
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class DiEngager extends DiSkillV2 {
    // makes the AI burp n  times per hour at random times
    private int burpsPerHour = 2;
    private TrgMinute trgMinute = new TrgMinute(0);
    private String skillToEngage = "unknown";
    private DrawRndDigits draw = new DrawRndDigits();
    private LGFIFO<Integer> burpMinutes = new LGFIFO<>();
    private PlayGround pl = new PlayGround();
    public DiEngager(int burpsPerHour, String skillToEngage) {
        super();
        if((burpsPerHour >0)&& (burpsPerHour <60)){
            this.burpsPerHour = burpsPerHour;
        }
        for (int i = 1; i < 60; i++) {
            draw.addElement(i);
        }
        for (int i = 0; i < burpsPerHour; i++) {
            burpMinutes.add(draw.draw());
        }
        this.skillToEngage = skillToEngage;
    }

    public void setSkillToEngage(String skillToEngage) {
        this.skillToEngage = skillToEngage;
    }

    @Override
    public void input(String ear, String skin, String eye) {
        // night? do not burp
        if (pl.partOfDay().equals("night")){
            return;
        }
        // reset burps
        if (trgMinute.trigger()){
            burpMinutes.clear();
            draw.reset();
            for (int i = 0; i < burpsPerHour; i++) {
                burpMinutes.add(draw.draw());
            }
            return;
        }
        // burp
        int nowMinutes = pl.getMinutesAsInt();
        if(burpMinutes.contains(nowMinutes)){
            burpMinutes.removeItem(nowMinutes);
            this.kokoro.toHeart.put(skillToEngage, "engage");
        }
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class DiEngager extends DiSkillV2 {
    // makes the AI burp n  times per hour at random times
    private int burpsPerHour = 2;
    private TrgMinute trgMinute = new TrgMinute(0);
    private String skillToEngage = "unknown";
    private DrawRndDigits draw = new DrawRndDigits();
    private LGFIFO<Integer> burpMinutes = new LGFIFO<>();
    private PlayGround pl = new PlayGround();
    public DiEngager(int burpsPerHour, String skillToEngage) {
        super();
        if((burpsPerHour >0)&& (burpsPerHour <60)){
            this.burpsPerHour = burpsPerHour;
        }
        for (int i = 1; i < 60; i++) {
            draw.addElement(i);
        }
        for (int i = 0; i < burpsPerHour; i++) {
            burpMinutes.add(draw.draw());
        }
        this.skillToEngage = skillToEngage;
    }

    public void setSkillToEngage(String skillToEngage) {
        this.skillToEngage = skillToEngage;
    }

    @Override
    public void input(String ear, String skin, String eye) {
        // night? do not burp
        if (pl.partOfDay().equals("night")){
            return;
        }
        // reset burps
        if (trgMinute.trigger()){
            burpMinutes.clear();
            draw.reset();
            for (int i = 0; i < burpsPerHour; i++) {
                burpMinutes.add(draw.draw());
            }
            return;
        }
        // burp
        int nowMinutes = pl.getMinutesAsInt();
        if(burpMinutes.contains(nowMinutes)){
            burpMinutes.removeItem(nowMinutes);
            this.kokoro.toHeart.put(skillToEngage, "engage");
        }
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Swift:
import Foundation

class DiEngager: DiSkillV2 {
    private var burpsPerHour = 2
    private var trgMinute = TrgMinute(0)
    private var skillToEngage = "unknown"
    private var draw = DrawRndDigits()
    private var burpMinutes = LGFIFO<Int>()
    private var pl = PlayGround()
    
    init(burpsPerHour: Int, skillToEngage: String) {
        super.init()
        if burpsPerHour > 0 && burpsPerHour < 60 {
            self.burpsPerHour = burpsPerHour
        }
        for i in 1..<60 {
            draw.addElement(i)
        }
        for _ in 0..<burpsPerHour {
            burpMinutes.add(draw.draw())
        }
        self.skillToEngage = skillToEngage
    }
    
    func setSkillToEngage(skillToEngage: String) {
        self.skillToEngage = skillToEngage
    }
    
    override func input(ear: String, skin: String, eye: String) {
        if pl.partOfDay() == "night" {
            return
        }
        
        if trgMinute.trigger() {
            burpMinutes.clear()
            draw.reset()
            for _ in 0..<burpsPerHour {
                burpMinutes.add(draw.draw())
            }
            return
        }
        
        let nowMinutes = pl.getMinutesAsInt()
        if burpMinutes.contains(nowMinutes) {
            burpMinutes.removeItem(nowMinutes)
            self.kokoro.toHeart[skillToEngage] = "engage"
        }
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class DrawRndDigits {
    // draw a random integer, than takes said element out
    private var strings:Array<Int> = [Int]()
    private var stringsSource:Array<Int> = [Int]()
    init(_ values:Int...) {
        for temp in values {
            strings.append(temp)
            stringsSource.append(temp)
        }
    }
    func draw() -> Int {
        if strings.isEmpty {return -1}
        let x:Int = Int.random(in: 0..<strings.count)
        let element:Int = strings[x]
        strings.remove(at: x)
        return element
    }
    func reset(){
        let dc:DeepCopier = DeepCopier()
        strings = dc.copyListOfInts(original: stringsSource)
    }
    func getSimpleRNDNum(bound:Int)->Int{
        // return 0->bound-1
        return Int.random(in: 0...bound-1)
    }
    func addElement(element:Int) {
        strings.append(element)
        stringsSource.append(element)
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class DiEngager: DiSkillV2 {
    private var burpsPerHour = 2
    private var trgMinute = TrgMinute(minute: 0)
    private var skillToEngage = "unknown"
    private var draw = DrawRndDigits()
    private var burpMinutes:Array<Int> = [Int]()
    private var pl = PlayGround()
    
    init(burpsPerHour: Int, skillToEngage: String) {
        super.init()
        if burpsPerHour > 0 && burpsPerHour < 60 {
            self.burpsPerHour = burpsPerHour
        }
        for i in 1..<60 {
            draw.addElement(element: i)
        }
        for _ in 0..<burpsPerHour {
            burpMinutes.append(draw.draw())
        }
        self.skillToEngage = skillToEngage
    }
    
    func setSkillToEngage(skillToEngage: String) {
        self.skillToEngage = skillToEngage
    }
    
    override func input(ear: String, skin: String, eye: String) {
        if pl.partOfDay() == "night" {
            return
        }
        
        if trgMinute.trigger() {
            burpMinutes.removeAll()
            draw.reset()
            for _ in 0..<burpsPerHour {
                burpMinutes.append(draw.draw())
            }
            return
        }
        
        let nowMinutes = pl.getMinutesAsInt()
        if burpMinutes.contains(nowMinutes) {
            // snippet of code : remove item from array list
            burpMinutes.removeAll {value in return value == nowMinutes}
            self.kokoro.toHeart[skillToEngage] = "engage"
        }
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class GamificationP extends DiSkillV2 {
    // the grind side of the game, see GamificationN for the reward side
    private int gain = 1;
    private DiSkillV2 skill;
    private AXGamification axGamification = new AXGamification();

    public GamificationP(DiSkillV2 skill) {
        this.skill = skill;
    }

    public void setGain(int gain) {
        if (gain >0){
            this.gain = gain;}
    }

    public AXGamification getAxGamification() {
        // shallow ref
        return axGamification;
    }

    @Override
    public void input(String ear, String skin, String eye) {
        skill.input(ear, skin, eye);
    }

    @Override
    public void output(Neuron noiron) {
        // skill activation increases gaming credits
        if (skill.pendingAlgorithm()) {axGamification.incrementBy(gain);}
        skill.output(noiron);
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Swift:
class GamificationP: DiSkillV2 {
    private var gain = 1
    private var skill: DiSkillV2
    private var axGamification = AXGamification()
    
    init(skill: DiSkillV2) {
        self.skill = skill
    }
    
    func setGain(gain: Int) {
        if gain > 0 {
            self.gain = gain
        }
    }
    
    func getAxGamification() -> AXGamification {
        return axGamification
    }
    
    override func input(ear: String, skin: String, eye: String) {
        skill.input(ear: ear, skin: skin, eye: eye)
    }
    
    override func output(noiron: Neuron) {
        if skill.pendingAlgorithm() {
            axGamification.incrementBy(gain: gain)
        }
        skill.output(noiron: noiron)
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class GamificationP: DiSkillV2 {
    private var gain = 1
    private var skill: DiSkillV2
    private var axGamification = AXGamification()
    
    init(skill: DiSkillV2) {
        self.skill = skill
    }
    
    func setGain(gain: Int) {
        if gain > 0 {
            self.gain = gain
        }
    }
    
    func getAxGamification() -> AXGamification {
        return axGamification
    }
    
    override func input(ear: String, skin: String, eye: String) {
        skill.input(ear: ear, skin: skin, eye: eye)
    }
    
    override func output(noiron: Neuron) {
        if skill.pendingAlgorithm() {
            axGamification.incrementBy(amount: gain)
        }
        skill.output(noiron: noiron)
    }
}
 

fukurou

the supreme coder
ADMIN
Java:
public class GamificationN extends DiSkillV2 {
    private AXGamification axGamification;
    private int cost = 3;
    private DiSkillV2 skill;

    public GamificationN(DiSkillV2 skill, GamificationP rewardBank) {
        this.skill = skill;
        axGamification = rewardBank.getAxGamification();
    }

    public GamificationN setCost(int cost) {
        this.cost = cost;return this;
    }

    @Override
    public void input(String ear, String skin, String eye) {
        // engage skill only if a reward is possible
        if (axGamification.surplus(cost)){skill.input(ear, skin, eye);}
    }

    @Override
    public void output(Neuron noiron) {
        // charge reward if an algorithm is pending
        if (skill.pendingAlgorithm()) {axGamification.reward(cost);skill.output(noiron);}
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class GamificationN: DiSkillV2 {
    private var axGamification: AXGamification
    private var cost = 3
    private var skill: DiSkillV2
    
    init(skill: DiSkillV2, rewardBank: GamificationP) {
        self.skill = skill
        axGamification = rewardBank.getAxGamification()
    }
    
    func setCost(_ cost: Int) -> GamificationN {
        self.cost = cost
        return self
    }
    
    override func input(_ ear: String, _ skin: String, _ eye: String) {
        if axGamification.surplus(cost) {
            skill.input(ear, skin, eye)
        }
    }
    
    override func output(_ noiron: Neuron) {
        if skill.pendingAlgorithm() {
            axGamification.reward(cost)
            skill.output(noiron)
        }
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class DiPunisher extends DiSkillV2 {
    public DrawRnd punishments = new DrawRnd();
    private String trigger = "i was a bad boy";
    private TrgTime reset = new TrgTime();

    public void setTrigger(String trigger) {
        this.trigger = trigger;
    }

    public DiPunisher() {
        punishments.addElement("20 minutes of corner time");
        punishments.addElement("write 20 lines that say i was a bad boy");
        punishments.addElement("try to be good from now on sweety");
        reset.setTime("11:05");
    }

    @Override
    public void input(String ear, String skin, String eye) {
        if (reset.alarm()){punishments.reset();return;}
        if(ear.equals(trigger)){
            setVerbatimAlg(4, punishments.draw());
        }
    }
}
 
Top