reverse engineering the Neuro Sama persistent question algorithm

fukurou

the supreme coder
ADMIN

Code:
PersistantQuestion

active?
mode // key
{key,DrawRnd}
activate(){}
process(t:Str)->Str{
 // got answer?
 if dic.containsKey(t){mode = t; active = false;}
 // nag for answer:
 if outputDripper.drip() {result = dic[mode].drawRnd;
  if !reult.isEmpty {return result}
  else dic[mode].drawRnd.reset(); active = false;
 }
}

mode()->Str // end question event when !=""
{
 if active return ""
 return mode
}


// ensure the waifubot leaves time for user to reply between naggings
outputDriper()->Bool{
 return Cycler == 0
}
 

fukurou

the supreme coder
ADMIN
Java:
package AXJava;

public class OutputDripper {
    // drips true once every limit times
    // shushes the waifubot enough time to hear a reply from user
    private int cycler = 0;
    private int limit; // set to 1 for on off effect

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

    public int getLimit() {
        return limit;
    }

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

    public void reset() {
        cycler = limit;
    }
    public void setToZero(){cycler = 0;}
    public void sync(int n){
        if((n<-1)||(n>limit)){
            return;
        }
        cycler = n;
    }
}
 

fukurou

the supreme coder
ADMIN

Java:
package AXJava;

import java.util.Hashtable;

public class PersistantQuestion {
    private Boolean isActive = false;
    private String mode = "yes"; // key mode
    private Hashtable<String, DrawRnd>dic = new Hashtable<>();
    private OutputDripper outputDripper = new OutputDripper(1);
    public void addPath(String answer, DrawRnd nags){
        dic.put(answer,nags);
    }
    public void activate(){isActive = true;}
    public String process(String inp){
        // got answer?
        if (dic.containsKey(inp)){
            mode = inp;
            isActive = false;
            dic.get(mode).reset();
            return "okay"; // can extend code to reply key, rnd finalizer
        }
        // nag for answer
        if (!outputDripper.drip()) {return "";}
        String result = dic.get(mode).draw();
        if (!result.isEmpty()){return result;}
        else {dic.get(mode).reset();isActive = false; return "i see";}
    }
}

Java:
        PersistantQuestion persistantQuestion = new PersistantQuestion();
        persistantQuestion.addPath("yes",new DrawRnd("I love you", "do you love me?","please do you love me","you love me don't you ?"));
        persistantQuestion.addPath("no",new DrawRnd("you're annoying", "I'm leaving","good bye","you love me don't you ?"));
        persistantQuestion.activate();
        for (int i = 0; i < 10; i++) {
            System.out.println(persistantQuestion.process(""));
        }
        persistantQuestion.activate();
        System.out.println(persistantQuestion.process(""));
        System.out.println("answering no:");
        System.out.println(persistantQuestion.process("no"));
        persistantQuestion.activate();
        for (int i = 0; i < 10; i++) {
            System.out.println(persistantQuestion.process(""));
        }
    }

output:

you love me don't you ?

I love you

do you love me?

please do you love me

i see

do you love me?
answering no:
okay

I'm leaving

good bye

you're annoying

you love me don't you ?

i see

Process finished with exit code 0
:s45:
 

fukurou

the supreme coder
ADMIN
I personally hate when someone asks me if I love them, it usually results with me cutting them out my life.
but I'm a puzzle junkie so I solved it.

it also pisses me off, when ppl don't know or don't explain how something works. they think chat modules are some
movie tear complex skynet omni algorithms.

they will still think that, the average joe doesn't have the capacity to brain dive.

I do. most of the times it gives me a high when I manage to dive back up. sometimes I get stuck for months and it a horrible feeling. the germans had a word for it: "froitzenflakh"
 
Top