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

93
LINES

< > BotCompany Repo | #1002408 // Turing Test Bot

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

Libraryless. Click here for Pure Java version (2245L/15K/49K).

!759

static new L<S> turingTests;

p {
  load("turingTests");
}

synchronized answer {
  if "turing score" ret getTuringScore();
  if "turing tests" ret structure(turingTests);
  if "tests running" ret structure(testsRunning); // TODO: solve the sync problem
  try answer manageSnippetList(s, "turing test", "turingTests");
  
  if "run turing test *" {
    S id = m.fsi(0);
    if (!turingTests.contains(id))
      ret "Not a turing test: " + id;
    runTestAsync(id);
    S url = mainURL() + "1002408?id=" + parseSnippetID(id);
    ret "Test " + shortSnippetLink(id) + " running. Check result here: " + url;
  }
}

static S html(S subUri, Map<S, S> params) {
  L<S> keepFields = litlist();
  S protocolID = params.get("id");
  
  S html = htag("p", "Eleutheria's current Turing score: " + htag("b", getTuringScore()));
  
  html += htag("p", "Tests running: " + structure(testsRunning));
  
  if (isSnippetID(protocolID)) {
    S protocol = loadTextFile(getProgramFile(protocolID, "protocol-" + urlencode(getTuringScore_eleuURL)));

    html += tag("h3", "Protocol of " + quote(getSnippetTitle(protocolID)) + " (" + formatSnippetID(protocolID) + ")") +
      sourceCodeToHTML(protocol);
  }
  
  html += tag("h3", "Tests");
  html += "<ul>";
  for (S id : turingTests)
    html += tag("li", 
      tag("a", formatSnippetID(id) + " - " + getSnippetTitle(id), "href", selfLink(params, keepFields, "id", "" + parseSnippetID(id))) + " " +
      tag("a", "[source]", "href", "http://tinybrain.de/" + parseSnippetID(id)));
  html += "</ul>";
  
  ret html;
}

static S snippetLink(S id) {
  ret tag("a", formatSnippetID(id) + " - " + getSnippetTitle(id), "href", "http://tinybrain.de/" + parseSnippetID(id));
}

static S getTuringScore_eleuURL = "http://bots.tinybrain.de/1002076/raw";

static S getTuringScore() {
  long s = 0, n = 0;
  int tests = 0;
  for (S testID : turingTests) pcall {
    PersistentMap<S, O> scores = new PersistentMap(testID, "turing-scores.map");
    O score = scores.get(getTuringScore_eleuURL);
    if (score == null) continue;
    s += (long) get(score, "score");
    n += (long) get(score, "n");
    ++tests;
  }
  S result = s + " of " + n + " points (" + n(tests, "test");
  int notRun = l(turingTests)-tests;
  if (notRun > 0)
    result += ", " + notRun + " not run yet";
  ret result + ")";
}

static L<S> testsRunning = synchroList();

static void runTestAsync(final S testID) {
  Runnable code = runnable {
    testsRunning.add(testID);
    try {
      Class test = main.hotwire(testID);
      setOpt(test, "mainBot", getMainBot()); // let test know that we are in Eleu process (allows for faster testing)
      callMain(test);
    } finally {
      testsRunning.remove(testID);
    }
  };
  O processManager = getBot("#1002558");
  if (processManager == null)
    new Thread(code).start();
  else
    call(processManager, "start", "Turing Test " + testID, code);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002408
Snippet name: Turing Test Bot
Eternal ID of this version: #1002408/1
Text MD5: 8ff7d3f3e1700378b6034d83d6c7450a
Transpilation MD5: 6706c45083d63e4dda9c3fcd5e1ddc6c
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-07 20:55:38
Source code size: 2991 bytes / 93 lines
Pitched / IR pitched: No / No
Views / Downloads: 855 / 2747
Referenced in: [show references]