static S url = "http://bots.tinybrain.de/1002076/raw"; static S param = "q"; static int delayPerQuestionMS = 50; // time for other threads to do something static new L> qlist; // questions and answers static new L protocol; static class TuringScore { S url; long score, n; long date; } static PersistentMap scores; // key = url p { scores = new PersistentMap("turing-scores.map"); tests(); prot("It is unix day " + unixDay() + " (timestamp " + unixTime() + "), and we are doing some Turing testing!"); prot("Test ID: " + formatSnippetID(getProgramID())); prot(); prot("Made " + n(l(qlist), "question") + "."); prot(); prot("Checking " + url + "..."); int score = 0; time { for (L qa : qlist) try { S q = qa.get(0), a = qa.get(1); long t = now(); S result = getAnswer(q); t = now()-t; result = htmldecode(result); S line = q + " => " + result + " [" + t + " ms]"; boolean ok = turingMatch(a, result); if (ok) { ++score; prot("OK " + line); } else prot("NOT OK expected: " + a + " - " + line); } catch (Throwable e) { prot(exceptionToUser(e)); } sleep(delayPerQuestionMS); } prot(""); prot("Time elapsed: " + lastTiming() + " ms"); prot(""); prot(format("Score for *: * / *", url, score, l(qlist))); new TuringScore ts; ts.date = now(); ts.url = url; ts.score = score; ts.n = l(qlist); logStructure(getProgramFile("turing-tests.log"), ts); scores.put(url, ts); saveTextFile(getProgramFile("protocol-" + urlencode(url)), fromLines(protocol)); } static void add(S q, boolean yes) { qlist.add(litlist(q, yes ? "yes" : "no")); } static void add(S q, long number) { qlist.add(litlist(q, str(number))); } static void add(S q, S s) { qlist.add(litlist(q, s)); } static void prot(S s) { print(s); protocol.add(s); } static void prot() { prot(""); } static S getAnswer(S q) { O mainBot = getMainBot(); if (mainBot != null) { // give us a dialog ID! callOpt(getOpt(mainBot, "dialogID"), "set", "turing-" + getProgramID()); ret (S) call(mainBot, "answer", q); } else ret loadPage(url + "?" + makePostData(param, q)); }