Skip to content

Commit

Permalink
fixed antiwordle bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuval Ben-Hayun authored and Yuval Ben-Hayun committed Nov 14, 2022
1 parent c83b48b commit ffb092a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 104 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<script type = "text/javascript" src = "js/main.js"></script>
<script type = "text/javascript" src = "js/bot.js"></script>
<script type = "text/javascript" src = "https://ybenhayun.github.io/general.js"></script>
<script type = "text/javascript" src = "../webpage/general.js"></script>
<title>WordleBot</title>
</head>
<body>
Expand Down
30 changes: 18 additions & 12 deletions js/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<div class = 'average'></div><div class = 'current'></div>";
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 += "<div class = 'bar'><span class = 'num-guesses'>" + (i+1) + "</span><span class = 'count'></span></div>";
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 += "<div class = 'bar x'><span class = 'num-guesses'>X" + "</span><span class = 'count'></span></div>";
Expand All @@ -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 = "<div class = 'disclaimer'>If the bot starts out slow, don't worry. It will get increasingly faster as it plays more games.</div>";
let submit_button = "<button class = 'bot'>Start WordleBot</button>";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.";

Expand Down
8 changes: 1 addition & 7 deletions js/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,7 @@ function setRowDifferencesWithPositions(coloring, row) {
}
}

// Woodle Specific Functions & Constants
const TRACKER_BUTTONS = `<div class = 'tracker'>
<select name='woodle-count' class = 'woodle-count G'></select>
<select name='woodle-count' class = 'woodle-count Y'></select>
</div>`


// Woodle Specific Functions
function woodleDropdown(row) {
let selector = row.getElementsByClassName('woodle-count');
for (let i = 0; i < selector.length; i++) {
Expand Down
71 changes: 41 additions & 30 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -279,9 +280,13 @@ function writeBestGuessList(guesses, list_length) {
}

function createListItem(word, data, rank) {
let name = "<div class = 'suggestion click' onclick='enterGuess("+JSON.stringify(word)+")'>" + rank + ". " + word + ": </div>";
let score = "<div class = 'score'>" + data + "</div>";
return "<li>" + name + score + "</li>";
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) {
Expand Down Expand Up @@ -322,19 +327,17 @@ function createAnswerDropdown(likely_answers, unlikely_answers) {
technically_words.innerHTML = "<p>" + unlikely_list + "</p>";

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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 += "<button class = 'B tile " + bot.type + "'>" + word[i] + "</button>";
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 = "<button class = 'undo'>remove last guess</button>";
buttons += "<button class = 'filter'>calculate next guess</button>";
Expand All @@ -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');
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit ffb092a

Please sign in to comment.