aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / public / js / turing-game.js
| 1 | // The Turing, as a game you can play in thirty seconds. |
| 2 | // |
| 3 | // A hidden rule generates a stream of bits. You call each next bit before |
| 4 | // it lands. A correct call earns 1 T, a miss costs 1 T, and a coin flip |
| 5 | // averages zero: exactly the idea behind the measure. Memorizing is |
| 6 | // useless here because every bit is new; only finding the rule pays. |
| 7 | (function () { |
| 8 | "use strict"; |
| 9 | |
| 10 | var ROUNDS = 12; |
| 11 | |
| 12 | // Each generator is a small hidden rule over the bit history. |
| 13 | // firstBits are shown for free so the pattern can be spotted. |
| 14 | var RULES = [ |
| 15 | { |
| 16 | name: "alternation", |
| 17 | firstBits: [0, 1, 0, 1, 0, 1], |
| 18 | next: function (h) { return h[h.length - 1] ^ 1; } |
| 19 | }, |
| 20 | { |
| 21 | name: "growing runs", |
| 22 | firstBits: [0, 1, 1, 0, 0, 0], |
| 23 | next: function (h) { |
| 24 | // Run lengths grow by one: 0, 11, 000, 1111, 00000, ... |
| 25 | var last = h[h.length - 1]; |
| 26 | var s = h.length - 1; |
| 27 | while (s > 0 && h[s - 1] === last) s--; |
| 28 | var runsBefore = 0, i = 0; |
| 29 | while (i < s) { |
| 30 | var j = i; |
| 31 | while (j < s && h[j] === h[i]) j++; |
| 32 | runsBefore++; |
| 33 | i = j; |
| 34 | } |
| 35 | var trailing = h.length - s; |
| 36 | return trailing < runsBefore + 1 ? last : last ^ 1; |
| 37 | } |
| 38 | }, |
| 39 | { |
| 40 | name: "xor of the last two", |
| 41 | firstBits: [0, 1, 1, 0, 1, 1], |
| 42 | next: function (h) { return h[h.length - 1] ^ h[h.length - 2]; } |
| 43 | }, |
| 44 | { |
| 45 | name: "pairs", |
| 46 | firstBits: [1, 1, 0, 0, 1, 1], |
| 47 | next: function (h) { |
| 48 | var last = h[h.length - 1]; |
| 49 | var prev = h[h.length - 2]; |
| 50 | return last === prev ? last ^ 1 : last; |
| 51 | } |
| 52 | } |
| 53 | ]; |
| 54 | |
| 55 | var streamEl, scoreEl, roundEl, msgEl, btn0, btn1, btnReset; |
| 56 | var history, rule, score, round, finished; |
| 57 | |
| 58 | function render() { |
| 59 | streamEl.textContent = history.join(" ") + " ?"; |
| 60 | scoreEl.textContent = (score > 0 ? "+" : "") + score + " T"; |
| 61 | roundEl.textContent = "Round " + round + " / " + ROUNDS; |
| 62 | } |
| 63 | |
| 64 | function start() { |
| 65 | rule = RULES[Math.floor(Math.random() * RULES.length)]; |
| 66 | history = rule.firstBits.slice(); |
| 67 | score = 0; |
| 68 | round = 0; |
| 69 | finished = false; |
| 70 | btn0.disabled = false; |
| 71 | btn1.disabled = false; |
| 72 | btn0.style.opacity = "1"; |
| 73 | btn1.style.opacity = "1"; |
| 74 | msgEl.textContent = |
| 75 | "Six bits are on the table for free. The rest are yours to predict. " + |
| 76 | "Right call: +1 T. Miss: -1 T. A coin flip averages zero."; |
| 77 | render(); |
| 78 | } |
| 79 | |
| 80 | function verdict() { |
| 81 | if (score >= 8) { |
| 82 | return "That is one part of understanding. A short rule in your head just compressed a stream you had never seen, and it paid out in Turings. The full measure, with sealed data and recomputable receipts, is in the paper."; |
| 83 | } |
| 84 | if (score >= 3) { |
| 85 | return "You are finding the pattern. That climb, from guessing to predicting, is exactly what the Turing measures. Memorizers cannot do it on new data."; |
| 86 | } |
| 87 | if (score >= -2) { |
| 88 | return "About coin-flip territory, which is the point: guessing earns nothing under this unit. The rule was there. Try a fresh stream and hunt for it."; |
| 89 | } |
| 90 | return "Below chance this time. The stream beat you, and the scoreboard said so honestly. That honesty is the whole idea: the Turing only pays for real prediction."; |
| 91 | } |
| 92 | |
| 93 | function guess(bit) { |
| 94 | if (finished) return; |
| 95 | var actual = rule.next(history); |
| 96 | history.push(actual); |
| 97 | round++; |
| 98 | if (bit === actual) { |
| 99 | score += 1; |
| 100 | msgEl.textContent = "Called it. +1 T. The next bit is already hidden."; |
| 101 | } else { |
| 102 | score -= 1; |
| 103 | msgEl.textContent = "It landed " + actual + ". -1 T. Adjust the rule in your head and call the next one."; |
| 104 | } |
| 105 | if (round >= ROUNDS) { |
| 106 | finished = true; |
| 107 | btn0.disabled = true; |
| 108 | btn1.disabled = true; |
| 109 | btn0.style.opacity = "0.5"; |
| 110 | btn1.style.opacity = "0.5"; |
| 111 | streamEl.textContent = history.join(" "); |
| 112 | scoreEl.textContent = (score > 0 ? "+" : "") + score + " T"; |
| 113 | roundEl.textContent = "Stream complete"; |
| 114 | msgEl.textContent = verdict(); |
| 115 | return; |
| 116 | } |
| 117 | render(); |
| 118 | } |
| 119 | |
| 120 | document.addEventListener("DOMContentLoaded", function () { |
| 121 | streamEl = document.getElementById("tg-stream"); |
| 122 | if (!streamEl) return; |
| 123 | scoreEl = document.getElementById("tg-score"); |
| 124 | roundEl = document.getElementById("tg-round"); |
| 125 | msgEl = document.getElementById("tg-msg"); |
| 126 | btn0 = document.getElementById("tg-zero"); |
| 127 | btn1 = document.getElementById("tg-one"); |
| 128 | btnReset = document.getElementById("tg-reset"); |
| 129 | btn0.addEventListener("click", function () { guess(0); }); |
| 130 | btn1.addEventListener("click", function () { guess(1); }); |
| 131 | btnReset.addEventListener("click", start); |
| 132 | start(); |
| 133 | }); |
| 134 | })(); |