👨‍💻 dev C++ port

development

owly

闇の伝説
Staff member
戦闘 コーダー
project progress at 47.06%
 
0% 100%

1. AbsDictionaryDB +
2. Mutatable +
3. APSay:Mutatable +
4. APVerbatim:Mutatable +
5. GrimoireMemento +
6. Algorithm +
7. Kokoro +
8. Neuron +
9. DiSkillUtils
10. DiSkillV2
11. DiHelloWorld:DiSkillV2 // logical skill for testing
12. Cerabellum
13. Fusion
14. Thinkable
15. Chobits:Thinkable
16. Brain
17. DiSysOut // hardware skill for testing
 
Last edited by a moderator:

fukurou

the supreme coder
ADMIN
C++:
#include <iostream>
#include <string>
#include <typeinfo>
#include <cxxabi.h>
#include <algorithm>
using namespace std;

class AbsDictionaryDB {
public:
    virtual std::string save(const std::string& key, const std::string& value) {
        // Returns action string (override me)
        return "";
    }

    virtual std::string load(const std::string& key) {
        return "null";
    }

    virtual ~AbsDictionaryDB() = default; // Virtual destructor for proper cleanup
};

class Mutatable {
public:
    bool algKillSwitch = false;

    virtual std::string action(const std::string& ear, const std::string& skin, const std::string& eye) {
        return "";
    }

    virtual bool completed() {
        // Has finished?
        return false;
    }

    std::string myName() {
        // Returns the class name
        int status;
        char* demangledName = abi::__cxa_demangle(typeid(*this).name(), 0, 0, &status);
        std::string result(demangledName);
        free(demangledName);
        return result;
    }

    virtual ~Mutatable() = default; // Virtual destructor for proper cleanup
};
class APSay : public Mutatable {
private:
    int at;
    std::string param;

public:
    APSay(int at, const std::string& param) : Mutatable() {
        if (at > 10) {
            at = 10;
        }
        this->at = at;
        this->param = param;
    }

    std::string action(const std::string& ear, const std::string& skin, const std::string& eye) {
        std::string axnStr = "";
        if (this->at > 0) {
            std::string earLower = ear;
            std::transform(earLower.begin(), earLower.end(), earLower.begin(), ::tolower);
            std::string paramLower = this->param;
            std::transform(paramLower.begin(), paramLower.end(), paramLower.begin(), ::tolower);
            if (earLower != paramLower) {
                axnStr = this->param;
                this->at -= 1;
            }
        }
        return axnStr;
    }

    bool completed() const {
        return this->at < 1;
    }
};
 

fukurou

the supreme coder
ADMIN
C++:
#include <iostream>
#include <string>
#include <vector>
#include <typeinfo>
#include <cxxabi.h>
class APVerbatim : public Mutatable {
private:
    std::vector<std::string> sentences;
    int at;

public:
    APVerbatim(std::initializer_list<std::string> args) : Mutatable(), at(0) {
        if (args.size() == 1 && args.begin()->empty()) {
            this->at = 30;
        } else {
            for (const auto& arg : args) {
                this->sentences.push_back(arg);
            }
        }
    }

    std::string action(const std::string& ear, const std::string& skin, const std::string& eye) override {
        std::string axnStr = "";
        if (this->at < this->sentences.size()) {
            axnStr = this->sentences[this->at];
            this->at += 1;
        }
        return axnStr;
    }

    bool completed() const {
        return this->at >= this->sentences.size();
    }
};
 

fukurou

the supreme coder
ADMIN
C++:
class GrimoireMemento {
private:
    AbsDictionaryDB* absDictionaryDB;

public:
    GrimoireMemento(AbsDictionaryDB* absDictionaryDB) : absDictionaryDB(absDictionaryDB) {}

    std::string simpleLoad(const std::string& key) {
        return absDictionaryDB->load(key);
    }

    void simpleSave(const std::string& key, const std::string& value) {
        if (key.rfind("AP", 0) == 0 || key.empty() || value.empty()) {
            return;
        }
        absDictionaryDB->save(key, value);
    }
};
 

fukurou

the supreme coder
ADMIN
C++:
#include <vector>
#include <string>

class Algorithm {
private:
    std::vector<Mutatable*> algParts;

public:
    // Constructor
    Algorithm(const std::vector<Mutatable*>& algParts) : algParts(algParts) {}

    // Getter for algParts
    const std::vector<Mutatable*>& getAlgParts() const {
        return algParts;
    }

    // Method to get the size of algParts
    int getSize() const {
        return algParts.size();
    }
};
 

fukurou

the supreme coder
ADMIN
C++:
#include <map>
#include <vector>
#include <memory>

public:
    Neuron() {
        for (int i = 1; i <= 5; ++i) {
            _defcons[i] = std::vector<std::shared_ptr<Algorithm>>();
        }
    }

    void insertAlg(int priority, std::shared_ptr<Algorithm> alg) {
        if (priority > 0 && priority < 6) {
            if (_defcons[priority].size() < 4) {
                _defcons[priority].push_back(alg);
            }
        }
    }

    std::shared_ptr<Algorithm> getAlg(int defcon) {
        if (_defcons[defcon].size() > 0) {
            std::shared_ptr<Algorithm> temp = _defcons[defcon].front();
            _defcons[defcon].erase(_defcons[defcon].begin());
            return temp;
        }
        return nullptr;
    }
};
 
Top