From 874d6321c955b2be037ac20d7f6b895d3d53be25 Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Thu, 30 Nov 2023 18:35:07 -0500 Subject: ok --- static/script.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'static/script.js') diff --git a/static/script.js b/static/script.js index c40298c..23ee2b2 100644 --- a/static/script.js +++ b/static/script.js @@ -4,13 +4,19 @@ var currentBoard = null; var selected = {}; function newGroup() { - var keys = Object.keys(corpus); - var i = keys.length * Math.random() << 0; - var group = corpus[keys[i]]; - var clues = randomSelect(group.clues, 4); + var categoryPoint = Math.random(); + for (var category of corpus) { + if (categoryPoint < category.portion) { + continue; + } + var group = category.groups[category.groups.length * Math.random() << 0] + var clues = randomSelect(group.clues, 4) + console.log(category.name) + break; + } return { - group: group.group, + hint: group.hint, clues: clues, fullClues: group.clues, }; @@ -33,7 +39,11 @@ function newBoard() { var group = newNonintersectingGroup(groups); groups.push(group); } - return groups; + var newGroups = []; + for (var i = 0; i < 4; i++) { + newGroups.push({hint: groups[i].hint, clues: groups[i].clues}); + } + return newGroups; } function chooseBox(box) { @@ -74,7 +84,7 @@ function consume(grp) { document.getElementById('answers').innerHTML += `
-
${group.group}
+
${group.hint}
${group.clues.map(renderClue).join(', ')}
`; } @@ -101,7 +111,7 @@ function serializeBoard(board) { for (var group of board) { copy.push({ clues: group.clues, - group: group.group, + hint: group.hint, }) } return encodeURIComponent(btoa(JSON.stringify(copy))) @@ -113,8 +123,7 @@ function deserializeBoard(s) { for (var group of copy) { board.push({ clues: group.clues, - group: group.group, - fullClues: group.clues, + hint: group.hint, }) } return board; -- cgit v1.2.3