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).

1  
!759
2  
3  
static new L<S> turingTests;
4  
5  
p {
6  
  load("turingTests");
7  
}
8  
9  
synchronized answer {
10  
  if "turing score" ret getTuringScore();
11  
  if "turing tests" ret structure(turingTests);
12  
  if "tests running" ret structure(testsRunning); // TODO: solve the sync problem
13  
  try answer manageSnippetList(s, "turing test", "turingTests");
14  
  
15  
  if "run turing test *" {
16  
    S id = m.fsi(0);
17  
    if (!turingTests.contains(id))
18  
      ret "Not a turing test: " + id;
19  
    runTestAsync(id);
20  
    S url = mainURL() + "1002408?id=" + parseSnippetID(id);
21  
    ret "Test " + shortSnippetLink(id) + " running. Check result here: " + url;
22  
  }
23  
}
24  
25  
static S html(S subUri, Map<S, S> params) {
26  
  L<S> keepFields = litlist();
27  
  S protocolID = params.get("id");
28  
  
29  
  S html = htag("p", "Eleutheria's current Turing score: " + htag("b", getTuringScore()));
30  
  
31  
  html += htag("p", "Tests running: " + structure(testsRunning));
32  
  
33  
  if (isSnippetID(protocolID)) {
34  
    S protocol = loadTextFile(getProgramFile(protocolID, "protocol-" + urlencode(getTuringScore_eleuURL)));
35  
36  
    html += tag("h3", "Protocol of " + quote(getSnippetTitle(protocolID)) + " (" + formatSnippetID(protocolID) + ")") +
37  
      sourceCodeToHTML(protocol);
38  
  }
39  
  
40  
  html += tag("h3", "Tests");
41  
  html += "<ul>";
42  
  for (S id : turingTests)
43  
    html += tag("li", 
44  
      tag("a", formatSnippetID(id) + " - " + getSnippetTitle(id), "href", selfLink(params, keepFields, "id", "" + parseSnippetID(id))) + " " +
45  
      tag("a", "[source]", "href", "http://tinybrain.de/" + parseSnippetID(id)));
46  
  html += "</ul>";
47  
  
48  
  ret html;
49  
}
50  
51  
static S snippetLink(S id) {
52  
  ret tag("a", formatSnippetID(id) + " - " + getSnippetTitle(id), "href", "http://tinybrain.de/" + parseSnippetID(id));
53  
}
54  
55  
static S getTuringScore_eleuURL = "http://bots.tinybrain.de/1002076/raw";
56  
57  
static S getTuringScore() {
58  
  long s = 0, n = 0;
59  
  int tests = 0;
60  
  for (S testID : turingTests) pcall {
61  
    PersistentMap<S, O> scores = new PersistentMap(testID, "turing-scores.map");
62  
    O score = scores.get(getTuringScore_eleuURL);
63  
    if (score == null) continue;
64  
    s += (long) get(score, "score");
65  
    n += (long) get(score, "n");
66  
    ++tests;
67  
  }
68  
  S result = s + " of " + n + " points (" + n(tests, "test");
69  
  int notRun = l(turingTests)-tests;
70  
  if (notRun > 0)
71  
    result += ", " + notRun + " not run yet";
72  
  ret result + ")";
73  
}
74  
75  
static L<S> testsRunning = synchroList();
76  
77  
static void runTestAsync(final S testID) {
78  
  Runnable code = runnable {
79  
    testsRunning.add(testID);
80  
    try {
81  
      Class test = main.hotwire(testID);
82  
      setOpt(test, "mainBot", getMainBot()); // let test know that we are in Eleu process (allows for faster testing)
83  
      callMain(test);
84  
    } finally {
85  
      testsRunning.remove(testID);
86  
    }
87  
  };
88  
  O processManager = getBot("#1002558");
89  
  if (processManager == null)
90  
    new Thread(code).start();
91  
  else
92  
    call(processManager, "start", "Turing Test " + testID, code);
93  
}

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: 859 / 2753
Referenced in: [show references]