Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

122
LINES

< > BotCompany Repo | #1013876 // Katze Oder Nichtkatze Bot [dev.]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (21820L/156K).

!7

sS yesName = "Katze";
sS noName = "Nichtkatze";

sS yesText = [[
  Katze
  Cat
  Captain
]];

sS noText = [[
  Bier
  Hallo
  Kalt
]];

static Set<S> yesLiterals = ciSet(), noLiterals = ciSet();

static Bool algo_0_1(S s) {
  if (yesLiterals.contains(s)) true;
  if (noLiterals.contains(s)) false;
  null;
}

static Bool algo_0_2(S s) {
  s = trim(s);
  try bool algo_0_1(s);
  S s2 = collapseWord(s);
  if (neq(s, s2))
    try bool algo_0_1(s2);
  null;
}

static Bool algo_0_3(S s) {
  try bool algo_0_2(s);
  S s2 = firstWord(s);
  if (neq(s, s2))
    try bool algo_0_2(s);
  null;
}

p {
  autoRestart();
  independentSmartBot();
  onNewTriple(f onTriple);
  sahara();
  consoleHeight(500);
  showMessagesInGerman(true);
  logModuleOutput();
  readLinePrefix("[] Eingabe: ");
  addAll_withCollapsed(yesLiterals, tlftj(yesText));
  addAll_withCollapsed(noLiterals, tlftj(noText));
  for (T3<S> t : triplesWithB("heißt")) onTriple(t);
  bot();
  centerBigConsole2();
  focusConsole(random(tossCoin() ? yesLiterals : noLiterals);
  controls2_default();
}

svoid controls_feedback(S text) {
  disableConsoleInput();
  hideControls2();
  showControls(withCenteredTitle("Ich glaube:",
    vstackWithSpacing(setFontSize(15, jcenteredBoldLabel(text)),
  centeredButtons(
    "Das ist korrekt", r {
      print("=> KORREKT");
      uploadOutputSinceLastInput();
      reset();
    },
    "Das ist nicht korrekt", r {
      print("=> INKORREKT");
      fS s = lastInput();
      //uploadOutputSinceLastInput();
      
      showControls(vstackWithSpacing(
        setFontSize(13, jcenteredBoldLabel("Was heißt " + quote(s) + " denn?")),
        jcenteredbuttons(
          "Es heißt " + yesName, r { correct(s, true) },
          "Es heißt " + noName, r { correct(s, false) },
          "Es heißt was anderes", r { correct(s, null) })));
    }))));
}

answer {
  Bool b = algo_0_3(s);
  S a = formatSatz(s, b);
  controls_feedback(a);
  try answer a;
}

sS formatSatz(S s, Bool b) {
  ret quote(s) + " " + (
      isTrue(b) ? "bedeutet '" + yesName + "'"
    : isFalse(b) ? "bedeutet '" + noName + "'"
    : "bedeutet weder " + yesName + " noch " + noName);
}

svoid controls2_default() {
  showControls2(jcenteredlabel("Schreib doch mal was " + yesName + "-iges oder " + noName + "-iges:"));
}

svoid correct(S input, Bool b) {
  print(formatSatz(input, b));
  post(quote(input), "heißt", boolSwitch(b, yesName, noName, "weder " + yesName + " noch " + noName));
  uploadOutputSinceLastInput();
  reset();
}

svoid reset { 
  hideControls();
  enableConsoleInput();
  focusConsole();
}

svoid onTriple(T3<S> t) {
  if (eqic(t.b, "heißt") && isQuoted(t.a)) {
    if (eqic(t.c, yesName)) add_withCollapsed(yesLiterals, unquote(t.a));
    else if (eqic(t.c, noName)) add_withCollapsed(noLiterals, unquote(t.a));
  }
}

Author comment

Began life as a copy of #1013840

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1013876
Snippet name: Katze Oder Nichtkatze Bot [dev.]
Eternal ID of this version: #1013876/1
Text MD5: 7e32a30c07195f11b2b71f4f2a1bbea9
Transpilation MD5: e9156cb9c29020475cd6077ccf03e2c3
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-03-09 14:29:13
Source code size: 2940 bytes / 122 lines
Pitched / IR pitched: No / No
Views / Downloads: 535 / 1842
Referenced in: #1013882 - Beleidung oder nicht Bot