👨‍💻 dev AXPython pt2

development

owly

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

+1 AlgDispenser
+2 AXFriend
+3 AXLearnability
+4 AXPassword
+5 ButtonEngager
+6 Catche
+7 CombinatoricalUtils
+8 Cycler
+9 DrawRnd
+10 EmoDetectorCurious
+11 EmoDetectorHappy
+12 EmoDetectorStressed
+13 ForcedLearn
+14 InputFilter
+15 LGTypeConverter
+16 Map
+17 Responder
+18 SkillHubAlgDispenser
+19 SpiderSense
+20 TrgEV3
+21 TrgMinute
+22 TrgParrot
+23 TrgSnooze
24 TrgTime
+25 TrgTolerance
+26 UniqueItemSizeLimitedPriorityQueue
+27 UniqueItemPriorityQue
+28 EV3DaisyChainOrMode
+29 EV3DaisyChainAndMode

@fukurou
 
Last edited by a moderator:

fukurou

the supreme coder
ADMIN
Python:
class AXNightRider:
    # night rider display simulation for LED lights count up than down
    def __init__(self, limit: int):
        self._mode: int = 0
        self._position: int = 0
        self._lim = 0
        if limit > 0:
            self._lim = limit
        self._direction = 1

    def setLim(self, lim: int):
        # number of LEDs
        self._lim = lim

    def setMode(self, mode: int):
        # room for more modes to be added
        if 10 > mode > -1:
            self._mode = mode

    def getPosition(self) -> int:
        match self._mode:
            case 0:
                self.mode0()
        return self._position

    def mode0(self):
        # clasic night rider display
        self._position += self._direction
        if self._direction < 1:
            if self._position < 1:
                self._position = 0
                self._direction = 1
        else:
            if self._position > self._lim - 1:
                self._position = self._lim
                self._direction = -1
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class CombinatoricalUtils {
    public ArrayList<String> result;

    public ArrayList<String> getResult() {
        return result;
    }

    private void generatePermutations(ArrayList<ArrayList<String>> lists, List<String> result, int depth, String current) {
        if (depth == lists.size()) {
            result.add(current);
            return;
        }

        for (int i = 0; i < lists.get(depth).size(); i++) {
            generatePermutations(lists, result, depth + 1, current + lists.get(depth).get(i));
        }
    }
    public void generatePermutations(ArrayList<ArrayList<String>> lists){
        result = new ArrayList<String>();
        generatePermutations(lists, this.result, 0, "");
    }
    public void generatePermutations(ArrayList<String>... lists){
        ArrayList<ArrayList<String>> ll = new ArrayList<ArrayList<String>>();
        for (int i = 0; i < lists.length; i++) {
            ll.add(lists[i]);
        }
        result = new ArrayList<String>();
        generatePermutations(ll, this.result, 0, "");
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class CombinatoricalUtils:
    # combo related algorithmic tools
    def __init__(self):
        self.result: list[str] = []

    def _generatePermutations(self, lists: list[list[str]], result: list[str], depth: int, current: str):
        # this function has a private modifier (the "_" makes it so)
        if depth == len(lists):
            result.append(current)
            return
        for i in range(0, len(lists) + 1):
            self._generatePermutations(lists, result, depth + 1, current + lists[depth][i])

    def generatePermutations(self, lists: list[list[str]]):
        # generate all permutations between all string lists in lists, which is a list of lists of strings
        self.result = []
        self._generatePermutations(lists, self.result, 0, "")

    def generatePermutations(self, *lists: list[list[str]]):
        # this is the varargs vertion of this function
        # example method call: cu.generatePermutations(l1,l2)
        temp_lists:list[list[str]] = []
        for i in range(0, len(lists)):
            temp_lists.append(lists[i])
        self.result = []
        self._generatePermutations(temp_lists, self.result, 0, "")
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class Cycler {
    // cycles through numbers limit to 0 non-stop
    private int cycler = 0;
    private int limit;

    public Cycler(int limit) {
        super();
        this.limit = limit;
        cycler = limit;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }
    public int cycleCount() {
        cycler--;
        if (cycler < 0) {
            cycler = limit;
        }
        return cycler;
    }

    public void reset() {
        cycler = limit;
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class Cycler:
    # cycles through numbers limit to 0 non-stop
    def __init__(self, limit: int):
        self.limit: int = limit
        self._cycler: int = limit

    def cycleCount(self) -> int:
        self._cycler -= 1
        if self._cycler < 0:
            self._cycler = self.limit
        return self._cycler

    def reset(self):
        self._cycler = self.limit
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
import java.util.ArrayList;
import java.util.Random;

public class Responder {
    // simple random response dispenser
    private ArrayList<String> responses = new ArrayList<String>();
    private Random rand = new Random();
    public Responder(String... replies) {
        for (int i = 0; i < replies.length; i++) {
            responses.add(replies[i]);
        }
    }
    public String getAResponse(){
        if (responses.isEmpty()){
            return "";
        }
        return responses.get(rand.nextInt(responses.size()));
    }
    public Boolean responsesContainsStr(String str){
        return responses.contains(str);
    }
    public Boolean strContainsResponse(String str){
        Boolean result = false;
        for (String tempStr: responses) {
            if (str.contains(tempStr)){
                result = true;
                break;
            }
        }
        return result;
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class Responder:
    # simple random response dispenser
    def __init__(self, *replies: str):
        self.responses: list[str] = []
        for response in replies:
            self.responses.append(response)

    def getAResponse(self) -> str:
        if not self.responses:
            return ""
        return self.responses[random.randint(0,len(self.responses) -1)]

    def responsesContainsStr(self, item: str) -> bool:
        return self.responses.__contains__(item)

    def strContainsResponse(self, item: str) -> bool:
        for response in self.responses:
            if item.__contains__(response):
                return True
        return False
 
Last edited:

owly

闇の伝説
Staff member
戦闘 コーダー
Python:
public class ForcedLearn {
   // remembers key inputs because they start with keyword
   // also can dispense key inputs
    public String keyword = "say";
    private LGFIFO<String> p1 = new LGFIFO<String>();
    private RegexUtil ru = new RegexUtil();
    private int queLimit = 5;

    public int getQueLimit() {
        return queLimit;
    }

    public void setQueLimit(int queLimit) {
        if(!(queLimit>0)){return;}
        this.queLimit = queLimit;
    }
    public void input(String in1){
        if (keyword.equals(ru.firstWord(in1))){
            p1.add(in1.replace(keyword,""));
            if (p1.size()>queLimit){
                p1.poll();
            }
        }
    }
    public String getRandomElement(){
        if (p1.isEmpty()){return "";}
        return p1.getRNDElement();
    }
    public Boolean contains(String item){
        return p1.contains(item);
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class ForcedLearn(UniqueItemSizeLimitedPriorityQueue):
    '''remembers key inputs because they start with keyword
   // also can dispense key inputs'''

    def __init__(self, queLimit: int):
        super().__init__(queLimit)
        self._regexUtil: RegexUtil = RegexUtil()
        self.keyword: str = "say"

    # override
    def insert(self, data):
        temp: str = self._regexUtil.afterWord(self.keyword, data)
        if not temp == "":
            super().insert(temp)
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class EV3DaisyChainAndMode extends TrGEV3{
    // this class connects several logic gates triggers together
    private ArrayList<TrGEV3> trgGates = new ArrayList<TrGEV3>();

    public EV3DaisyChainAndMode(TrGEV3... gates) {
        for (TrGEV3 gate : gates)
        {
            trgGates.add(gate);
        }
    }

    @Override
    public void input(String ear, String skin, String eye) {
        for (TrGEV3 gate : trgGates)
        {
            gate.input(ear, skin, eye);
        }
    }

    @Override
    public void reset() {
        for (TrGEV3 gate : trgGates)
        {
            gate.reset();
        }
    }

    @Override
    public Boolean trigger() {
        for (TrGEV3 gate : trgGates)
        {
            if(!gate.trigger()){
                // not all gates return true
                return false;
            }
        }
        // all gates return true
        return true;
    }
}

Java:
public class EV3DaisyChainOrMode extends TrGEV3{
    // this class connects several logic gates triggers together
    private ArrayList<TrGEV3> trgGates = new ArrayList<TrGEV3>();

    public EV3DaisyChainOrMode(TrGEV3... gates) {
        for (TrGEV3 gate : gates)
        {
            trgGates.add(gate);
        }
    }

    @Override
    public void input(String ear, String skin, String eye) {
        for (TrGEV3 gate : trgGates)
        {
            gate.input(ear, skin, eye);
        }
    }

    @Override
    public void reset() {
        for (TrGEV3 gate : trgGates)
        {
            gate.reset();
        }
    }

    @Override
    public Boolean trigger() {
        for (TrGEV3 gate : trgGates)
        {
            if(gate.trigger()){
                // at least 1 gate is engaged
                return true;
            }
        }
        // all gates are not engaged
        return false;
    }
}
 

fukurou

the supreme coder
ADMIN

:s27:
Python:
class EV3DaisyChainAndMode(TrGEV3):
    # this class connects several logic gates triggers together
    def __init__(self, gates: TrGEV3):
        self._trgGates: list[TrGEV3] = []
        for gate in gates:
            self._trgGates.append(gate)

    # override
    def input(self, ear: str, skin: str, eye: str):
        for gate in self._trgGates:
            gate.input(ear, skin, eye)

    # override
    def reset(self):
        for gate in self._trgGates:
            gate.reset()

    # override
    def trigger(self) -> bool:
        for gate in self._trgGates:
            if not gate.trigger():
                # not all gates return true
                return False
            # all gates return true
            return True


class EV3DaisyChainOrMode(TrGEV3):
    # this class connects several logic gates triggers together
    def __init__(self, gates: TrGEV3):
        self._trgGates: list[TrGEV3] = []
        for gate in gates:
            self._trgGates.append(gate)

    # override
    def input(self, ear: str, skin: str, eye: str):
        for gate in self._trgGates:
            gate.input(ear, skin, eye)

    # override
    def reset(self):
        for gate in self._trgGates:
            gate.reset()

    # override
    def trigger(self) -> bool:
        for gate in self._trgGates:
            if gate.trigger():
                # at least 1 gate is engaged
                return True
            # all gates are not engaged
            return False
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class InputFilter {
    // filter out non-relevant input
    // or filter in relevant data
    public String filter(String ear, String skin, String eye){
        // override me
        return "";
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class InputFilter:
    """filter out non-relevant input
    or filter in relevant data"""

    def input(self, ear: str, skin: str, eye: str) -> str:
        # override me
        pass
 
Top