/* ZimiGames: Babel. One everyday word, shown in other languages, a clue at a time: French "eau", Russian "вода", Japanese "水". Name it in English. You start with two clues; a wrong guess or a tap on Another clue shows one more (up to five), and the sooner you get it the more you score (4, 3, 2 or 1). Five words a game. With an English Wiktionary in the library (Zimi or kiwix-serve) the languages are those its Translations section lists for the word, a different five every time; elsewhere they are the words of babel-data.js. The rules are pure functions (no DOM, so node can test them), then the page. Our own code, GPL-3.0. */ (function (root) { 'use strict'; var Lib = root.GamesLib; // ── the rules ──────────────────────────────────────────────────────────── var ROUNDS = 5, CLUES = 5, START_CLUES = 2, MAX_LATIN = 2, PAGE_BYTES = 700000, WORD_MAX = 24, TOP_POINTS = CLUES + 1; var SCRIPTS = [['latin', /[A-Za-zÀ-ɏ]/], ['cyrillic', /[Ѐ-ӿ]/], ['greek', /[Ͱ-Ͽ]/], ['arabic', /[-ۿ]/], ['hebrew', /[-]/], ['devanagari', /[ऀ-ॿ]/], ['hangul', /[가-]/], ['kana', /[-ヿ]/], ['han', /[一-鿿]/]]; function scriptOf(word) { for (var i = 0; i < SCRIPTS.length; i++) if (SCRIPTS[i][1].test(word)) return SCRIPTS[i][0]; return 'other'; } // The points for naming it when `shown` clues are showing: 4 for two, then 3, 2, 1. function pointsFor(shown) { return Math.max(1, TOP_POINTS - shown); } function plain(h) { return ZimiUtil.sweep(h, /<[^>]*>/g).replace(/ | /g, ' ').replace(/&(?!amp;)#?\w+;/g, ' ').replace(/&/g, '&').replace(/\s+/g, ' ').trim(); } // The translations in an English Wiktionary page (or its /translations subpage): the first Translations table's lines, each // "Language: word (how it is said)". [{code, name, word, tr}], one per language. function parseTranslations(html) { var src = String(html || ''), at = src.search(/class="[^"]*\btranslations\b[^"]*"/i); if (at < 0) return []; var rest = src.slice(at), end = rest.search(/<\/table>/i); if (end > 0) rest = rest.slice(0, end); var out = [], seen = {}, re = /