diff options
Diffstat (limited to 'static/script.js')
| -rw-r--r-- | static/script.js | 29 | 
1 files changed, 19 insertions, 10 deletions
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 +=          `<div class="answer"> -            <div class="answerline">${group.group}</div> +            <div class="answerline">${group.hint}</div>              <div class="clues">${group.clues.map(renderClue).join(', ')}</div>          </div>`;  } @@ -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;  | 
