(swift) he looks to the left he looks to the right

fukurou

the supreme coder
ADMIN
Java:
public class AXCmdBreaker {
    // separate command parameter from the command
    public String conjuration;

    public AXCmdBreaker(String conjuration) {
        this.conjuration = conjuration;
    }
    public String extractCmdParam(String s1){
        if (s1.contains(conjuration)){
            return s1.replace(conjuration,"").trim();
        }
        return "";
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXCmdBreaker{
    // separate command parameter from the command
    var conjuration:String
    init(conjuration: String) {
        self.conjuration = conjuration
    }
    func extractCmdParam(s1:String)->String{
        if s1.contains(conjuration){
            return s1.replacingOccurrences(of: conjuration, with: "").trimmingCharacters(in: .whitespacesAndNewlines)
        }
        return ""
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class AXInputWaiter {
    // wait for any input
    private TrgTolerance trgTolerance;

    public AXInputWaiter(int tolerance) {
        this.trgTolerance = new TrgTolerance(tolerance);
        trgTolerance.reset();
    }
    public void reset(){
        trgTolerance.reset();
    }
    public Boolean wait(String s1){
        // return true till any input detected or till x times of no input detection
        if (!s1.isEmpty()){
            return false;
        }
        return trgTolerance.trigger();
    }
    public void setWait(int timesToWait){
        trgTolerance.setMaxrepeats(timesToWait);
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TrgTolerance {
    // this boolean gate will return true till depletion or reset()
    var maxRepeats:Int
    var repeats:Int = 0
    init(maxRepeats:Int) {
        self.maxRepeats = maxRepeats
    }
    func setMaxRepeats(maxRepeats:Int){
        self.maxRepeats = maxRepeats
        reset()
    }
    @discardableResult
    func trigger() -> Bool{
        // will return true till depletion or reset()
        repeats -= 1
        if (repeats > 0) {
            return true
        }
        return false
    }
    func reset() {
        // refill trigger
        self.repeats = self.maxRepeats
    }
    func disable(){
        repeats = 0
    }
}

Swift:
class AXInputWaiter{
    // wait for any input
    private var trgTolerance:TrgTolerance
    init(tolerance: Int) {
        self.trgTolerance = TrgTolerance(maxRepeats: tolerance)
        self.trgTolerance.reset()
    }
    func reset(){
        self.trgTolerance.reset()
    }
    func wait(s1:String)->Bool{
        // return true till any input detected or till x times of no input detection
        if !s1.isEmpty {
            trgTolerance.disable()
            return false
        }
        return self.trgTolerance.trigger()
    }
    func setWait(timesToWait:Int){
        trgTolerance.setMaxRepeats(maxRepeats: timesToWait)
    }
}

patched an err :s44:
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class AXMachineCode {
    // common code lines used in machine code to declutter machine code
    public Hashtable<String,Integer> dic = new Hashtable<>();
    public AXMachineCode addKeyValuePair(String key, int value){
        dic.put(key,value);
        return this;
    }
    public int getMachineCodeFor(String key){
        return dic.getOrDefault(key,-1);
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXMachineCode{
    // common code lines used in machine code to declutter machine code
    var dic:[String:Int] = [:]
    @discardableResult
    func addKeyValuePair(key:String,value:Int)->AXMachineCode{
        dic[key] = value
        return self
    }
    func getMachineCodeFor(key:String)->Int{
        return dic[key, default: -1]
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class AXContextCmd {
    // engage on commands
    // when commands are engaged, context commans can also engage
    public UniqueItemSizeLimitedPriorityQueue commands = new UniqueItemSizeLimitedPriorityQueue();
    public UniqueItemSizeLimitedPriorityQueue contextCommands = new UniqueItemSizeLimitedPriorityQueue();
    public TrgTolerance trgTolerance  = new TrgTolerance(3);
    public Boolean engageCommand(String s1){
        if (commands.contains(s1)){
            trgTolerance.reset();
            return true;
        }
        if (!trgTolerance.trigger()){
            return false;
        }
        return contextCommands.contains(s1);
    }
    public void setInputWait(int thinkCycles){
        trgTolerance.setMaxrepeats(thinkCycles);
    }
    public void disable(){
        // context commands are disabled till next engagement with a command
        trgTolerance.disable();
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXContextCmd{
    // engage on commands
    // when commands are engaged, context commans can also engage
    public var commands:UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue()
    public var contextCommands:UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue()
    private var trgTolerance:TrgTolerance = TrgTolerance(maxRepeats: 3)
    func engageCommand(ear:String) -> Bool {
        if commands.contains(str: ear){
            trgTolerance.reset()
            return true
        }
        if !trgTolerance.trigger(){
            return false
        }
        return contextCommands.contains(str: ear)
    }
    func setInputWait(thinkCycles:Int){
        trgTolerance.setMaxRepeats(maxRepeats: thinkCycles)
    }
    func disable(){
        // context commands are disabled till next engagement with a command
        trgTolerance.disable()
    }
}
 
Top