port overlort python ->Swift assed edition!

fukurou

the supreme coder
ADMIN
Swift:
class PercentDripper {
    private var dr = DrawRnd()
    private var limis: Int = 35

    /// Set the base drip activation limit (0–100)
    func setLimit(_ limis: Int) {
        self.limis = limis
    }

    /// Returns true based on a percentage chance (`limis`%)
    func drip() -> Bool {
        return dr.getSimpleRNDNum(100) < limis
    }

    /// Returns true based on `limis + plus` chance
    func dripPlus(_ plus: Int) -> Bool {
        return dr.getSimpleRNDNum(100) < limis + plus
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// AXTimeContextResponder selects responses based on the current part of day.
class AXTimeContextResponder {
    private var morning = Responder()
    private var afternoon = Responder()
    private var evening = Responder()
    private var night = Responder()
    
    private var responders: [String: Responder]

    init() {
        responders = [
            "morning": morning,
            "afternoon": afternoon,
            "evening": evening,
            "night": night
        ]
    }

    /// Respond using the appropriate Responder for the current part of day.
    func respond() -> String {
        let part = TimeUtils.partOfDay()
        return responders[part]?.getAResponse() ?? ""
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class Magic8Ball {
    private var questions: Responder = Responder()
    private var answers: Responder = Responder()

    init() {
        // Affirmative responses
        answers.addResponse("It is certain")
        answers.addResponse("It is decidedly so")
        answers.addResponse("Without a doubt")
        answers.addResponse("Yes definitely")
        answers.addResponse("You may rely on it")
        answers.addResponse("As I see it, yes")
        answers.addResponse("Most likely")
        answers.addResponse("Outlook good")
        answers.addResponse("Yes")
        answers.addResponse("Signs point to yes")

        // Non-Committal responses
        answers.addResponse("Reply hazy, try again")
        answers.addResponse("Ask again later")
        answers.addResponse("Better not tell you now")
        answers.addResponse("Cannot predict now")
        answers.addResponse("Concentrate and ask again")

        // Negative responses
        answers.addResponse("Don’t count on it")
        answers.addResponse("My reply is no")
        answers.addResponse("My sources say no")
        answers.addResponse("Outlook not so good")
        answers.addResponse("Very doubtful")

        // Recognizable question patterns
        questions = Responder(
            "will i", "can i expect", "should i", "is it a good idea",
            "will it be a good idea for me to", "is it possible", "future hold",
            "will there be"
        )
    }

    func setQuestions(_ q: Responder) {
        questions = q
    }

    func setAnswers(_ a: Responder) {
        answers = a
    }

    func getQuestions() -> Responder {
        return questions
    }

    func getAnswers() -> Responder {
        return answers
    }

    func engage(_ ear: String) -> Bool {
        guard !ear.isEmpty else { return false }
        return questions.strContainsResponse(ear)
    }

    func reply() -> String {
        return answers.getAResponse()
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Learns 1-word inputs and returns a recently learned word
class Responder1Word {
    private var q = UniqueItemSizeLimitedPriorityQueue(limit: 5)

    init() {
        // Seed with some baby-babble classics
        q.insert("chi")
        q.insert("gaga")
        q.insert("gugu")
        q.insert("baby")
    }

    /// Learns a word if it's only one word (no spaces)
    func listen(_ ear: String) {
        if !ear.contains(" ") && !ear.isEmpty {
            q.insert(ear)
        }
    }

    /// Returns a random learned word
    func getAResponse() -> String {
        return q.getRNDElement()
    }

    /// Checks if the word exists in memory
    func contains(_ ear: String) -> Bool {
        return q.contains(ear)
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
// ╔════════════════════════════════════════════════════════════════════════╗
// ║                         STATE MANAGEMENT                               ║
// ╚════════════════════════════════════════════════════════════════════════╝
 

fukurou

the supreme coder
ADMIN
Swift:
class Prompt {
    private var kv = AXKeyValuePair()
    private var prompt: String = ""
    private var regex: String = ""

    init() {
        kv.key = "default"
    }

    func getPrompt() -> String {
        return prompt
    }

    func setPrompt(_ prompt: String) {
        self.prompt = prompt
    }

    func process(_ input: String) -> Bool {
        kv.value = RegexUtil.extractRegex(regex, input)
        return kv.value.isEmpty
    }

    func getKv() -> AXKeyValuePair {
        return kv
    }

    func setRegex(_ pattern: String) {
        regex = pattern
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXPrompt {
    private var isActive: Bool = false
    private var index: Int = 0
    private var prompts: [Prompt] = []
    private var kv: AXKeyValuePair? = AXKeyValuePair()

    /// Add a prompt to the sequence
    func addPrompt(_ p: Prompt) {
        prompts.append(p)
    }

    /// Get the current prompt's display string
    func getPrompt() -> String {
        guard !prompts.isEmpty else { return "" }
        return prompts[index].getPrompt()
    }

    /// Process input and move to next prompt if matched
    func process(_ input: String) {
        guard isActive, !prompts.isEmpty else { return }
        let success = prompts[index].process(input)
        if !success {
            kv = prompts[index].getKv()
            index += 1
        }
        if index == prompts.count {
            isActive = false
        }
    }

    /// Return true if actively prompting
    func getActive() -> Bool {
        return isActive
    }

    /// Retrieve the stored key-value pair, then clear it
    func getKv() -> AXKeyValuePair? {
        guard let currentKv = kv else { return nil }
        let result = AXKeyValuePair(key: currentKv.key, value: currentKv.value)
        kv = nil
        return result
    }

    /// Start prompting from the beginning
    func activate() {
        isActive = true
        index = 0
    }

    /// Stop the prompt cycle and reset index
    func deactivate() {
        isActive = false
        index = 0
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Common code lines used in machine logic to declutter
/// Also provides simplified extensions for dictionary actions
class AXMachineCode {
    private var dic: [String: Int] = [:]

    /// Adds a key-value pair to the internal dictionary
    /// Returns self to allow builder-style chaining
    @discardableResult
    func addKeyValuePair(_ key: String, _ value: Int) -> AXMachineCode {
        dic[key] = value
        return self
    }

    /// Retrieves the machine code for the given key or returns -1 if not found
    func getMachineCodeFor(_ key: String) -> Int {
        return dic[key] ?? -1
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Detects if a button was pressed (on edge change).
/// Disables physical engagement while the button remains pressed.
class ButtonEngager {
    private var prevState: Bool = false

    /// Returns true only once when button is newly pressed.
    func engage(_ btnState: Bool) -> Bool {
        if prevState != btnState {
            prevState = btnState
            if btnState {
                return true
            }
        }
        return false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Reacts to a contextual "shout out" once and disables itself after reply.
class AXShoutOut {
    private var isActive: Bool = false
    var handshake: Responder = Responder()

    /// Enable the shout out system—must be called to activate engagement
    func activate() {
        isActive = true
    }

    /// Returns true if `ear` matches a handshake phrase; disables after engagement
    func engage(_ ear: String) -> Bool {
        guard !ear.isEmpty else { return false }

        if isActive {
            if handshake.strContainsResponse(ear) {
                isActive = false
                return true  // matched handshake!
            }
        }

        // Unrelated input—shout out context expired
        isActive = false
        return false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// AXHandshake manages time-based shout-outs and user acknowledgment
class AXHandshake {
    private var trgTime = TrgTime()
    private var trgTolerance = TrgTolerance(10)
    private var shoutout = AXShoutOut()
    private var userName: String = ""
    private var dripper = PercentDripper()

    init() {
        // Default handshake triggers
        shoutout.handshake = Responder("what", "yes", "i am here")
    }

    // MARK: - Configuration

    /// When should the shout-out trigger? (e.g. "9:15")
    @discardableResult
    func setTimeStamp(_ timeStamp: String) -> AXHandshake {
        trgTime.setTime(timeStamp)
        return self
    }

    /// How many times can the user be prompted before timeout?
    @discardableResult
    func setShoutOutLim(_ lim: Int) -> AXHandshake {
        trgTolerance.setMaxRepeats(lim)
        return self
    }

    /// Set which responses count as successful handshakes
    @discardableResult
    func setHandShake(_ responder: Responder) -> AXHandshake {
        shoutout.handshake = responder
        return self
    }

    /// How frequently should the shout-out happen? (in percent)
    @discardableResult
    func setDripperPercent(_ n: Int) -> AXHandshake {
        dripper.setLimit(n)
        return self
    }

    /// Set the name of the user to shout out to
    @discardableResult
    func setUserName(_ name: String) -> AXHandshake {
        self.userName = name
        return self
    }

    // MARK: - Accessors

    func getUserName() -> String {
        return userName
    }

    // MARK: - Behavior

    /// Detects if a valid handshake reply was given
    func engage(_ ear: String) -> Bool {
        if trgTime.alarm() {
            trgTolerance.reset()
        }

        if shoutout.engage(ear) {
            trgTolerance.disable()
            return true
        }
        return false
    }

    /// Triggers the shout-out logic based on time, tolerance, and dripper chance
    func trigger() -> Bool {
        if trgTolerance.trigger() {
            if dripper.drip() {
                shoutout.activate()
                return true
            }
        }
        return false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Tracks the difference between sampled power levels.
class Differ {
    private var powerLevel: Int = 90
    private var difference: Int = 0

    /// Returns the last sampled power level.
    func getPowerLevel() -> Int {
        return powerLevel
    }

    /// Returns the most recent difference between samples.
    func getPowerLVDifference() -> Int {
        return difference
    }

    /// Clears the recorded power level difference.
    func clearPowerLVDifference() {
        difference = 0
    }

    /// Samples a new power level, calculating its delta from the previous value.
    func samplePowerLV(_ pl: Int) {
        difference = pl - powerLevel
        powerLevel = pl
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Detects directional changes between two observed string tokens
/// and returns a corresponding code.
class ChangeDetector {
    private let A: String
    private let B: String
    private var prev: Int = -1

    init(_ a: String, _ b: String) {
        self.A = a
        self.B = b
    }

    /// Returns:
    /// - 2 if change detected from A → B
    /// - 1 if change detected from B → A
    /// - 0 otherwise
    func detectChange(_ ear: String) -> Int {
        guard !ear.isEmpty else { return 0 }

        var current = 0
        if ear.contains(A) {
            current = 1
        } else if ear.contains(B) {
            current = 2
        } else {
            return 0
        }

        var result = 0
        if current == 1 && prev == 2 {
            result = 1
        } else if current == 2 && prev == 1 {
            result = 2
        }
        prev = current
        return result
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
// ╔════════════════════════════════════════════════════════════════════════╗
// ║                         LEARNABILITY                                   ║
// ╚════════════════════════════════════════════════════════════════════════╝
 

fukurou

the supreme coder
ADMIN
Swift:
/// Enables pattern-based event prediction and alert recognition
class SpiderSense {
    private var spiderSense: Bool = false
    private var events: UniqueItemSizeLimitedPriorityQueue
    private var alerts: UniqueItemSizeLimitedPriorityQueue
    private var previous: String = "null"

    init(_ limit: Int) {
        self.events = UniqueItemSizeLimitedPriorityQueue(limit: limit)
        self.alerts = UniqueItemSizeLimitedPriorityQueue(limit: limit)
    }

    /// Register a predictable event (builder-style)
    @discardableResult
    func addEvent(_ event: String) -> SpiderSense {
        events.insert(event)
        return self
    }

    /// Learn from input. Triggers prediction if pattern matches.
    func learn(_ input: String) {
        guard !input.isEmpty else { return }

        if alerts.contains(input) {
            spiderSense = true
            return
        }

        if events.contains(input) {
            alerts.insert(previous)
            return
        }

        previous = input
    }

    /// Has a prediction been triggered?
    func getSpiderSense() -> Bool {
        let temp = spiderSense
        spiderSense = false
        return temp
    }

    /// Returns shallow copy of alerts (direct queue reference)
    func getAlertsShallowCopy() -> [String] {
        return alerts.queue
    }

    /// Returns a deep copy of alert history
    func getAlertsClone() -> [String] {
        return alerts.queue.map { $0 }
    }

    /// Clear all alerts (e.g., diplomatic reset)
    func clearAlerts() {
        alerts.clear()
    }

    /// Checks if an input matches a known event
    func eventTriggered(_ input: String) -> Bool {
        return events.contains(input)
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Manages a pool of dynamic strategies drawn from a central responder
class Strategy {
    private var allStrategies: UniqueResponder
    private var strategiesLim: Int
    private var activeStrategy: UniqueItemSizeLimitedPriorityQueue

    init(_ allStrategies: UniqueResponder, _ strategiesLim: Int) {
        self.allStrategies = allStrategies
        self.strategiesLim = strategiesLim
        self.activeStrategy = UniqueItemSizeLimitedPriorityQueue(limit: strategiesLim)

        // Seed the active queue with strategies from the master source
        for _ in 0..<strategiesLim {
            activeStrategy.insert(allStrategies.getAResponse())
        }
    }

    /// Refreshes the active strategy pool with new randomized entries
    func evolveStrategies() {
        for _ in 0..<strategiesLim {
            activeStrategy.insert(allStrategies.getAResponse())
        }
    }

    /// Returns a random strategy from the active strategy list
    func getStrategy() -> String {
        return activeStrategy.getRNDElement()
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// Stores a log of notes and allows cyclical access
class Notes {
    private var log: [String] = []
    private var index: Int = 0

    /// Add a new note to the log
    func add(_ note: String) {
        log.append(note)
    }

    /// Clear all notes
    func clear() {
        log.removeAll()
    }

    /// Get the current note
    func getNote() -> String {
        return log.isEmpty ? "zero notes" : log[index]
    }

    /// Get the next note (cycling back to start if needed)
    func getNextNote() -> String {
        guard !log.isEmpty else { return "zero notes" }
        index = (index + 1) % log.count
        return log[index]
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
/// A limited-size dictionary used for short-term memory.
/// Evicts oldest entries based on insertion order.
class Catche {
    private var limit: Int
    private var keys: UniqueItemSizeLimitedPriorityQueue
    private var dict: [String: String] = [:]

    init(size: Int) {
        self.limit = size
        self.keys = UniqueItemSizeLimitedPriorityQueue(limit: size)
    }

    /// Inserts or updates a key-value pair. Evicts oldest if over capacity.
    func insert(key: String, value: String) {
        if dict.keys.contains(key) {
            dict[key] = value
            return
        }

        if keys.size() == limit, let oldest = keys.peak() {
            dict.removeValue(forKey: oldest)
        }

        keys.insert(key)
        dict[key] = value
    }

    /// Clears all memory
    func clear() {
        keys.clear()
        dict.removeAll()
    }

    /// Reads value for a key, or "null" if not found
    func read(_ key: String) -> String {
        return dict[key] ?? "null"
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
// ╔════════════════════════════════════════════════════════════════════════╗
// ║                            MISCELLANEOUS                               ║
// ╚════════════════════════════════════════════════════════════════════════╝
 

fukurou

the supreme coder
ADMIN
Swift:
/// A simple key-value pair representation
class AXKeyValuePair {
    private var key: String
    private var value: String

    init(key: String = "", value: String = "") {
        self.key = key
        self.value = value
    }

    func getKey() -> String {
        return key
    }

    func setKey(_ key: String) {
        self.key = key
    }

    func getValue() -> String {
        return value
    }

    func setValue(_ value: String) {
        self.value = value
    }

    /// String representation: key;value
    func toString() -> String {
        return "\(key);\(value)"
    }
}
 
Top