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

183
LINES

< > BotCompany Repo | #1007798 // Gunnar numbers [WORKS]

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

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

!7

sS theFacts = [[

  Gunnar number n is n plus 777 if n > 1.
  There is no Gunnar number with a negative index.
  There is no Gunnar number 0.
  Gunnar number 1 is 50.

  // Some technical stuff
  gmtzfidalveipfyx feyhbrhdeovmbvaw amcmxkgwhivbouqs
  pqnfhkzxoqkaoyqk sppxbuuqeetjmzuo
]];

sS theRiddle = [[
  What is Gunnar number 0?
  What is Gunnar number 1?
  What is Gunnar number 2?
  What is Gunnar number 3?
  What is Gunnar number 4?
]];

static S concepts = [[
  ["feyhbrhdeovmbvaw", "There is no X."],
  ["mtsrzasaoxrmicch", "X is Y if Z."],
  ["fgvvrzypbkqomktd", "X is Y."],
  ["sppxbuuqeetjmzuo", "X plus Y"],
  ["devwldetfsfylnod", "X with a negative index"],
  ["rgsamtbrhpcqowko", "Gunnar number X"],
  ["jxcubqjtqykhfvyo", "X - Y", "as in minus"],
  ["wdbphzfoxwlrhdyl", "X > Y"],
  ["urfkhwfasdaqqqse", "What is X?"],
  ["pqnfhkzxoqkaoyqk", "Operation X should be expanded."],
  ["amcmxkgwhivbouqs", "Something that doesn't exist"],
  ["yissyloatogavyuu", "Gunnar number"],
  ["gmtzfidalveipfyx", "Marker X implies label Y."]
]];

!include #1007689 // Web v2

static int saveInterval = 60000;
static new Web web;
static L<Lisp> facts;
static long lastSave, sizeSaved;

p-tt {
  setConsoleTitle(programTitle());
  load("web"); lastSave = sysNow();
  setFrameHeight(consoleFrame(), 400);
  centerConsole();
  //magellan();
  //graphite();
  //mistAqua();
  //moderateTheme();
  sahara();
  swing {
    setConsoleInput("What is Gunnar number 500?");
    consoleAddAskButton();
    focusConsole();
    final JLabel lblBrainSize = jRightAlignedLabel();
    addToConsole(lblBrainSize);
    awtEvery(lblBrainSize, 1000, r {
      lblBrainSize.setText("Brain Size: " + toM(fileSize(programFile("web.structure")), 1) + "MB");
    });
  }

  aiEnhancements();
  aiConcepts_noAutoClear();
  useConceptsDump(concepts);
  set englishToConceptLanguage_useBrackets;
  facts = clParse(linesToCL(theFacts));
  print(theFacts);
  useFacts(theFacts);
  //printNumberedLines(facts);
  print();
  
  for (S rid : toLinesFullTrim(theRiddle)) {
    print("? " + rid);
    print("  " + answer(rid));
  }
    
  makeBot();
  notDone();
}

static S answer(S rid) {
  if (eq(rid, "web")) { print(web); ret "OK"; }
  Lisp riddle = clParse(englishToConceptLanguage(rid));
  //print("# " + riddle);
  
  if (!riddle.is("urfkhwfasdaqqqse", "mrhggsmuykeceghd")) ret "huh?"; // What is X? // What is the decimal representation of X?
  Lisp mainConcept = riddle.get(0);

  // Make web
  web.node(mainConcept);
  web.relations(facts);
  
  int webSize = web.count();
  int cursor = 0;
  while licensed {
    //print("Web size: " + webSize);
    if (webSize != sizeSaved && sysNow() >= lastSave+saveInterval) {
      printWithoutNL("S");
      save("web");
      sizeSaved = webSize;
      lastSave = sysNow();
    } else
      printWithoutNL(".");
    if ((++cursor % 60) == 0) print();
    
    CriticalAction action = beginCriticalAction("Web Update");
    try {
      web_expandMarkers(web);
      web_expandOperations(web);
  
      for (Lisp rule : trueStatementsByHead("mtsrzasaoxrmicch")) {
        Lisp x = rule.get(0);
        for (WebNode node : cloneList(web.nodes)) {
          for (Lisp lbl : cloneList(node.labels)) {
            //print("Matching " + x + " and " + lbl);
            Map<S, Lisp> matches = lispMatch(x, lbl, ll("n"));
            if (matches != null) {
              //print("Rule match: " + struct(matches));
              Lisp bla = lispReplaceVars(rule.get(2), matches);
              if (checkACondition(bla)) {
                bla = lispReplaceVars(rule.get(1), matches);
                bla = lispCalculateDeep(bla);
                bla = web_insertNumbers(web, bla);
                //print("bla: " + bla);
                bla = lispCalculateDeep(bla);
                if (lispIsInt(bla))
                  node.addLabel(bla); // Found!
                else {
                  //print("Condition OK! Evaluating: " + bla);
                  web.node(bla);
                }
              }
            }
          }
        }
        //print("Node: " + node + ", condition: " + condition);
      }
    } finally {
      action.done();
    }
    
    int n = web.count();
    if (n == webSize) break;
    webSize = n;
  }
  print();
  
  // print question again
  if (cursor / 60 >= 10)
    print("? " + rid);
    
  // Answer question
  L<Lisp> l = listWithout(web.findNode(mainConcept).labels, mainConcept);
  //print("Labels: " + l);
  S s = chooseALabelToReturn(l);
  s = or2(conceptLanguageToEnglish(unquote(s)), "I don't know");
  ret s;
}

sS chooseALabelToReturn(L<Lisp> ll) {
  L<S> l = map(f clUnparse, ll);
  //print("  Labels: " + l);
  S s = findInteger(l);
  if (s == null) s = firstGlobalID(l);
  //if (s == null) s = random(l);
  if (s == null) ret s = first(l);
  ret s;
}

sbool checkACondition(Lisp l) false on exception {
  ret lispCalculateDeep(l).is("true");
}

svoid cleanMeUp {
  while (criticalActionsInFlight()) sleep(5);
  if (sizeSaved != web.count())
    save("web");
}

Author comment

Began life as a copy of #1007674

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: #1007798
Snippet name: Gunnar numbers [WORKS]
Eternal ID of this version: #1007798/4
Text MD5: e91ec476414ec40e0d4329af45a5dfee
Transpilation MD5: e168e953052abdecde4a6be618f71965
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-08 20:56:23
Source code size: 5203 bytes / 183 lines
Pitched / IR pitched: No / No
Views / Downloads: 626 / 1270
Version history: 3 change(s)
Referenced in: