From ffb092a2d6e198cd9620b968cf0e814fa7372a4a Mon Sep 17 00:00:00 2001 From: Yuval Ben-Hayun Date: Sun, 13 Nov 2022 23:04:05 -0500 Subject: [PATCH] fixed antiwordle bug --- index.html | 1 + js/bot.js | 30 +++++++++++-------- js/class.js | 8 +---- js/main.js | 71 ++++++++++++++++++++++++------------------- js/setup.js | 86 +++++++++++++++++++---------------------------------- wordl.css | 1 + 6 files changed, 93 insertions(+), 104 deletions(-) diff --git a/index.html b/index.html index 775af3e..a4aa444 100644 --- a/index.html +++ b/index.html @@ -25,6 +25,7 @@ + WordleBot diff --git a/js/bot.js b/js/bot.js index e634e2c..dcdeece 100644 --- a/js/bot.js +++ b/js/bot.js @@ -85,13 +85,20 @@ function createBarGraphs(max_guesses) { document.getElementById("results").remove(); } - let test_center = document.createElement("div"); - test_center.setAttribute("id", "results"); - test_center.setAttribute("class", "testing"); - test_center.innerHTML = "
"; + let average = createElement('div', '', 'average'); + let current = createElement('div', '', 'current'); + let test_center = createElement('div', '', 'testing', 'results'); + test_center.append(average); + test_center.append(current); for (let i = 0; i < max_guesses; i++) { - test_center.innerHTML += "
" + (i+1) + "
"; + let bar = createElement('div', '', 'bar') + let num_guesses = createElement('span', i+1, 'num-guesses'); + let count = createElement('span', '', 'count'); + + bar.append(num_guesses); + bar.append(count); + test_center.append(bar); } if (!bot.isFor(ANTI)) test_center.innerHTML += "
X" + "
"; @@ -117,12 +124,11 @@ function removeNonBotElements() { document.getElementById('hints') ); - document.getElementById("next-previous-buttons").innerHTML = ""; + clearHTML(document.getElementById('next-previous-buttons')); } function createBotMenu() { - let menu = document.createElement("div"); - menu.setAttribute("id", "test-settings"); + let menu = createElement('div', '', '', 'test-settings'); let hard = "
If the bot starts out slow, don't worry. It will get increasingly faster as it plays more games.
"; let submit_button = ""; @@ -150,8 +156,8 @@ function swapDiv(event, elem) { } function setupTest(word) { - if (bot.isFor(XORDLE) || bot.isFor(FIBBLE) || bot.getCount() > 1) { - // return; + if (bot.isFor(XORDLE) || bot.isFor(FIBBLE)) { + return; } TEST_SIZE = Math.min(500, common.length); @@ -199,7 +205,7 @@ function setupTest(word) { function placeTestRows(word) { makeTables(word, 'testing'); - document.getElementsByClassName("next-previous-buttons").innerHTML = ""; + clearHTML(document.getElementById('next-previous-buttons')); } function getTestAnswers(TEST_SIZE, random_answers) { @@ -274,7 +280,7 @@ function extendBarGraphs(current_length, new_max) { function showResults(guess, correct, total_tested, average, words_missed) { resetGuessRows(); - document.getElementsByClassName("average")[0].innerHTML = ""; + clearHTML(document.getElementsByClassName('average')[0]); let summary = guess + " solved " + correct + "/" + total_tested + " words with an average of " + average + " guesses per solve."; diff --git a/js/class.js b/js/class.js index 7e9e095..c948c92 100644 --- a/js/class.js +++ b/js/class.js @@ -323,13 +323,7 @@ function setRowDifferencesWithPositions(coloring, row) { } } -// Woodle Specific Functions & Constants -const TRACKER_BUTTONS = `
- - -
` - - +// Woodle Specific Functions function woodleDropdown(row) { let selector = row.getElementsByClassName('woodle-count'); for (let i = 0; i < selector.length; i++) { diff --git a/js/main.js b/js/main.js index 9065dbb..2b633a3 100644 --- a/js/main.js +++ b/js/main.js @@ -40,7 +40,7 @@ function setLength() { document.getElementById('word-entered').setAttribute('maxlength', word_length); document.getElementById('word-entered').value = ""; - document.getElementById('next-previous-buttons').innerHTML = ""; + clearHTML(document.getElementById('next-previous-buttons')); words = big_list.filter((a) => a.length == word_length); // words = official_guesses.slice(); // uncomment to use original wordle guess list @@ -128,7 +128,8 @@ function uniqueWordsFrom(list) { function dontNeedToCheck(answers, unique_answers) { return (answers.length <=2 && !bot.isFor(ANTI) && bot.getCount() == 1) - || unique_answers.length <= 2 || numberOfGuessesSoFar(0); + || (unique_answers.length <= 2 && !bot.isFor(ANTI)) + || numberOfGuessesSoFar(0) } function getPotentialGuessesAndAnswers(difficulty) { @@ -279,9 +280,13 @@ function writeBestGuessList(guesses, list_length) { } function createListItem(word, data, rank) { - let name = "
" + rank + ". " + word + ":
"; - let score = "
" + data + "
"; - return "
  • " + name + score + "
  • "; + let suggestion = createElement('span', word, 'click'); + let word_with_ranking = createElement('div', rank + ". " + suggestion.outerHTML, 'suggestion'); + let score = createElement('div', data, 'score'); + + + let list_item = createElement('li', word_with_ranking.outerHTML + score.outerHTML); + return list_item.outerHTML; } function enterGuess(word) { @@ -322,19 +327,17 @@ function createAnswerDropdown(likely_answers, unlikely_answers) { technically_words.innerHTML = "

    " + unlikely_list + "

    "; if (likely_answers.length < 1) { - potential_answers.innerHTML = ""; + clearHTML(potential_answers); } if (unlikely_answers.length < 1) { - technically_words.innerHTML = ""; + clearHTML(technically_words); } } +const NO_WORDS_LEFT_MESSAGE = "it doesn't look like we have this word. double check to make sure you all the clues you entered are correct."; function noWordsLeftMessage() { - let message = document.createElement('div'); - message.setAttribute('id', 'nowords'); - message.innerHTML = "it doesn't look like we have this word. double check to make sure you all the clues you entered are correct."; - + let message = createElement('div', NO_WORDS_LEFT_MESSAGE, '', 'nowords') return message.outerHTML; } @@ -373,10 +376,15 @@ function showFinalOptions(sorted, less_likely) { } function printAnswer(answer) { - if (typeof answer == 'string') return answer; - if (Array.isArray(answer)) return answer[0]; + if (typeof answer == 'string') { + return createElement('span', answer, 'click').outerHTML; + } - return answer.word1 + "/" + answer.word2; + if (Array.isArray(answer)) { + return printAnswer(array[0]); + } + + return printAnswer(answer.word1) + "/" + printAnswer(answer.word2); } // adds the heading, normal suggestsions, and hard suggestions @@ -448,18 +456,31 @@ function makeTables(val, c) { } function createRow(word, mode) { - let row = document.createElement('div'), text = ""; - row.setAttribute('class', 'row ' + mode + ' ' + bot.type); + let row = createElement('div', '', 'row ' + mode + ' ' + bot.type); + for (let i = 0; i < word.length; i++) { - text += ""; + let button = createElement('button', word.charAt(i), 'B tile ' + bot.type); + row.append(button); } - if (bot.isFor(WOODLE)) text += TRACKER_BUTTONS; + if (bot.isFor(WOODLE)) { + row.append(makeWoodleDropdowns()) + } - row.innerHTML = text; return row; } +function makeWoodleDropdowns() { + let container = createElement('div', '', 'tracker'); + let correct_count = createElement('select', '', 'woodle-count ' + CORRECT); + let wrong_spot_count = createElement('select', '', 'woodle-count ' + WRONG_SPOT); + + container.append(correct_count); + container.append(wrong_spot_count); + + return container; +} + function addButtons() { let buttons = ""; buttons += ""; @@ -482,7 +503,7 @@ function addButtons() { rows[rows.length-1].remove(); if (!rows.length) { - document.getElementById('next-previous-buttons').innerHTML = ""; + clearHTML(document.getElementById('next-previous-buttons')); let full_grid = document.getElementById('hints'); full_grid.classList.add('empty'); } @@ -778,16 +799,6 @@ function calculateAverageGuesses(current_word, results) { current_word.average = avg; } -function count(string, char) { - let count = 0; - - for (let i = 0; i < string.length; i++) { - if (string[i] == char) count++; - } - - return count; -} - /* FILTER FUNCTIONS */ function filterList(list, letters, reduced_filter, split) { diff --git a/js/setup.js b/js/setup.js index 9bee2b4..7dc895c 100644 --- a/js/setup.js +++ b/js/setup.js @@ -45,6 +45,10 @@ $(document).ready(function() { } }); + $(document).on('click', '.click', function() { + enterGuess($(this).html()); + }) + $(document).on('click', '.showlist', function() { if ($(this).children().hasClass("visible")) { ($(this).children().removeClass("visible")); @@ -63,7 +67,7 @@ function createPage() { function resetPage() { clearGrids(); - document.getElementById('next-previous-buttons').innerHTML = ""; + clearHTML(document.getElementById('next-previous-buttons')); update(); } @@ -71,7 +75,7 @@ function clearGrids() { let grids = document.getElementsByClassName('grid'); for (let i = 0; i < grids.length; i++) { - grids[i].innerHTML = ""; + clearHTML(grids[i]); } let full_grid = document.getElementById('hints'); @@ -115,11 +119,10 @@ function drawPage() { } function addGrid(hints) { - hints.innerHTML = ""; + clearHTML(hints); for (let i = 0; i < bot.getCount(); i++) { - let grid = document.createElement('div'); - grid.setAttribute('class', 'grid'); + let grid = createElement('div', '', 'grid'); hints.append(grid); } } @@ -188,8 +191,7 @@ function createExample() { let example_row = createRow('TRAIN', 'dummy'); bot.setRowColor('GBYBB', example_row); - let example_list = document.createElement('ul'); - example_list.setAttribute('class', 'word-list dummy'); + let example_list = createElement('ul', '', 'word-list dummy'); for (let i = 0; i < EXAMPLE_LIST.length; i++) { example_list.innerHTML += createListItem(EXAMPLE_LIST[i].word, EXAMPLE_LIST[i].score, i+1); @@ -199,43 +201,35 @@ function createExample() { } function createWrongExample() { - let example_wrong = document.createElement('ul'); - example_wrong.setAttribute('class', 'word-list dummy'); + let example_wrong = createElement('ul', '', 'word-list dummy'); example_wrong.innerHTML = createListItem(EXAMPLE_LIST[0].word, EXAMPLE_LIST[0].wrong, 1); return example_wrong; } function makeCloseButton(type) { - let close_button = document.createElement('button'); - close_button.setAttribute('class', type + ' close'); - + let close_button = createElement('button', '', type + ' close'); return close_button; } function createInfoParagraphs() { - let p1 = document.createElement('p'); - p1.innerHTML = `Simply enter in your last guess, click on the tiles until the colors match, hit calculate, - and the WordleBot will give you the best possible guesses from that point.` + let p1 = createElement('p', `Simply enter in your last guess, click on the tiles until the colors match, hit calculate, + and the WordleBot will give you the best possible guesses from that point.`); - let p2 = document.createElement('p'); - p2.innerHTML = `This means the best guess from this point would be ` + EXAMPLE_LIST[0].word + `, - and that you have an average of ` + EXAMPLE_LIST[0].score + `. If you see:` + let p2 = createElement('p', `This means the best guess from this point would be ` + EXAMPLE_LIST[0].word + `, + and that you have an average of ` + EXAMPLE_LIST[0].score + `. If you see:`); - let p3 = document.createElement('p'); - p3.innerHTML = `That means ` + EXAMPLE_LIST[0].word + ` will only solve 96.77% of the remaining possible answers within ` + bot.guessesAllowed() + ` guesses. - Generally speaking, you should only see this if you're playing on hard mode.` + let p3 = createElement('p', `That means ` + EXAMPLE_LIST[0].word + ` will only solve 96.77% of the remaining possible answers within ` + bot.guessesAllowed() + ` guesses. + Generally speaking, you should only see this if you're playing on hard mode.`); - let p4 = document.createElement('p'); - p4.innerHTML = `Want to see how good your starting word is? Click the - on the top right to get a good idea.` + let p4 = createElement('p', `Want to see how good your starting word is? Click the + on the top right to get a good idea.`); return [p1, p2, p3, p4] } function explainExample() { - let explanation = document.createElement('div'); - explanation.setAttribute('class', 'description'); + let explanation = createElement('div', '', 'description'); if (bot.isFor(WORDLE)) { explanation.innerHTML = 'T is in the correct position, A is in the word but not in the correct position, and R, I, and N are not in the word.' @@ -262,13 +256,8 @@ function createInfoPage() { let example_wrong = createWrongExample(); let paragraphs = createInfoParagraphs(); - let main_header = document.createElement('h3'); - main_header.setAttribute('class' , 'top-header'); - main_header.innerHTML = 'How does this Work?'; - - let sub_header = document.createElement('h3'); - sub_header.setAttribute('class', 'mini'); - sub_header.innerHTML = 'After each guess you should see something like this:' + let main_header = createElement('h3', 'How does this Work?', 'top-header'); + let sub_header = createElement('h3', 'After each guess you should see something like this:', 'mini'); info.append(close_button); // button to close screen info.append(main_header); // 'how does this work' @@ -288,7 +277,7 @@ function createInfoPage() { close_button.addEventListener('click', function() { info.classList.remove("display"); info.classList.add("back"); - info.innerHTML = ""; + clearHTML(info); }); } @@ -342,40 +331,27 @@ function createAnswerLists(div) { document.getElementById('answers').remove(); } - let answer_lists = document.createElement('div'); - answer_lists.setAttribute('id', 'answers'); + let answer_lists = createElement('div', '', '', 'answers'); createOptions(answer_lists); div.append(answer_lists); } function createOptions(div) { - let class_name = 'best-guesses'; - let best_guesses = document.createElement('div'); - best_guesses.setAttribute('class', class_name); - - let word_list = document.createElement('ul'); - word_list.setAttribute('class', 'word-list'); - best_guesses.append(word_list) + let best_guesses = createElement('div', '', 'best-guesses'); + let word_list = createElement('ul', '', 'word-list'); + best_guesses.append(word_list); div.append(best_guesses); } function createHardModeSwitch(div) { - let switch_label = document.createElement('div'); - switch_label.setAttribute('class', 'hard label'); - switch_label.innerHTML = "Show me the best guesses for 'Hard Mode': " - - let switch_container = document.createElement('label'); - switch_container.setAttribute('class', 'hard switch'); - - let switch_checkbox = document.createElement('input'); - switch_checkbox.setAttribute('id', 'mode'); + let switch_label = createElement('div', "Show me the best guesses for 'Hard Mode':", 'hard label'); + let switch_container = createElement('label', '', 'hard switch'); + let switch_slider = createElement('span', '', 'slider round'); + let switch_checkbox = createElement('input', '', '', 'mode'); switch_checkbox.setAttribute('type', 'checkbox'); - let switch_slider = document.createElement('span'); - switch_slider.setAttribute('class', 'slider round'); - switch_container.append(switch_checkbox); switch_container.append(switch_slider); diff --git a/wordl.css b/wordl.css index c01247c..00b1cc1 100644 --- a/wordl.css +++ b/wordl.css @@ -855,6 +855,7 @@ input:checked + .slider:before { .click:hover { cursor: pointer; filter: brightness(90%); + text-decoration: underline; } #hints {