Skip to content

Commit

Permalink
corrected general.js link
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuval Ben-Hayun authored and Yuval Ben-Hayun committed Nov 13, 2022
1 parent 4d2991f commit c83b48b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 35 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<script type = "text/javascript" src = "js/class.js"></script>
<script type = "text/javascript" src = "js/main.js"></script>
<script type = "text/javascript" src = "js/bot.js"></script>
<script type = "text/javascript" src = "../general.js"></script>
<script type = "text/javascript" src = "https://ybenhayun.github.io/general.js"></script>
<title>WordleBot</title>
</head>
<body>
Expand Down Expand Up @@ -79,7 +79,7 @@ <h3 class="mini-header">Choose Your Bot</h3>
<option value="Thirdle" class = "Thirdle">Thirdle</option>
<option value="Dordle" class = "Dordle">Dordle</option>
<option value="Quordle" class = "Quordle">Quordle</option>
<!-- <option value="Octordle" class = "Octordle">Octordle</option> -->
<option value="Octordle" class = "Octordle">Octordle</option>
</select>
</p>
</div>
Expand Down
67 changes: 54 additions & 13 deletions js/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function swapDiv(event, elem) {

function setupTest(word) {
if (bot.isFor(XORDLE) || bot.isFor(FIBBLE) || bot.getCount() > 1) {
return;
// return;
}

TEST_SIZE = Math.min(500, common.length);
Expand Down Expand Up @@ -213,12 +213,26 @@ function getTestAnswers(TEST_SIZE, random_answers) {

function getRandomAnswer(random_answers) {
let index = Math.floor(Math.random()*(common.length-1));
if (bot.isFor(DORDLE)) {
let index2 = index;
while (common[index2] == common[index]) {
index2 = Math.floor(Math.random()*(common.length-1));
if (bot.getCount() > 1) {
let indices = [index];

for (let i = 0; i < bot.getCount()-1; i++) {
let new_index = indices[0];

while (indices.includes(new_index)) {
new_index = Math.floor(Math.random()*(common.length-1));
}

indices.push(new_index);
}
return {word1: common[index], word2: common[index2]};

let answers = [];

for (let i = 0; i < bot.getCount(); i++) {
answers.push(common[indices[i]]);
}

return answers;
} else if (bot.isFor(XORDLE)) {
let pair_index = Math.round(Math.random()*(common.length-1));
if (bot.getDifference(common[index], common[pair_index]) == INCORRECT.repeat(word_length)) {
Expand Down Expand Up @@ -375,23 +389,35 @@ function printData(all_words, guess, average, time) {

function wordleBot(guess, answer, difficulty) {
let attempts = 1;
let found = false;
let correct = 0;

while (attempts <= bot.guessesAllowed(difficulty)) {
makeTables(guess, "testing");

let diff = bot.getDifference(guess, answer);
bot.setRowColor(diff, document.getElementsByClassName('row')[(attempts-1)*bot.getCount()]);
let diff;

if (bot.getCount() > 1) {
diff = getMultiDifference(guess, answer);
} else {
diff = [bot.getDifference(guess, answer)];
}

for (let i = 0; i < bot.getCount(); i++) {
let grid = document.getElementsByClassName('grid')[i];
bot.setRowColor(diff[i], grid.getElementsByClassName('row')[(attempts-1)]);
}


if (answerFound(guess, answer)) {
if (bot.isFor(XORDLE)) {
makeTables(otherAnswer(guess, answer), "testing");
bot.setRowColor(CORRECT.repeat(word_length), document.getElementsByClassName('row')[attempts])
}
if (!bot.isDordle || found) {

correct++;

if (correct == bot.getCount()) {
break;
} else {
found = true;
}
}
attempts++;
Expand All @@ -405,6 +431,17 @@ function wordleBot(guess, answer, difficulty) {
return attempts;
}

function getMultiDifference(guess, answers) {
let diffs = [];

for (let i = 0; i < answers.length; i++) {
let color = bot.getDifference(guess, answers[i]);
diffs.push(color);
}

return diffs;
}

function otherAnswer(answer, answers) {
if (answer == answers.word1) return answers.word2;
return answers.word1;
Expand All @@ -413,9 +450,13 @@ function otherAnswer(answer, answers) {
function answerFound(guess, answer) {
if (guess == answer) return true;

if (bot.isFor(XORDLE) || bot.isFor(DORDLE)) {
if (bot.isFor(XORDLE)) {
if (guess == answer.word1 || guess == answer.word2) return true;
}

if (bot.getCount() > 1) {
if (answer.includes(guess)) return true;
}

return false;
}
53 changes: 39 additions & 14 deletions js/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ function differencesWithPositions(word1, word2) {
}

function getDoubleDifference(guess, answers) {
// if (bot.isFor(DORDLE)) return dordleDifference(guess, answers);

let diff1 = bot.getDifference(guess, answers.word1);
let diff2 = bot.getDifference(guess, answers.word2);

Expand Down Expand Up @@ -467,7 +465,21 @@ function reducesListMost(answers, guesses, future_guess) {
let min = answers.length;

for (let i = 0; i < guesses.length; i++) {
let data = calculateAverageBucketSize(guesses[i], answers, min, future_guess)
let data;

if (bot.getCount() > 1 && typeof answers[0] == 'object') {
let data_per_list = [];

for (let j = 0; j < answers.length; j++) {
min = answers[j].length;
data_per_list.push(calculateAverageBucketSize(guesses[i], answers[j], min, future_guess));
}

data = averageBucketSizeFromAllLists(data_per_list);
} else {
data = calculateAverageBucketSize(guesses[i], answers, min, future_guess);
}

if (!data) continue;

min = Math.min(min, data.adjusted);
Expand All @@ -481,6 +493,30 @@ function reducesListMost(answers, guesses, future_guess) {
return best_words;
}

function averageBucketSizeFromAllLists(data) {
let differences = {};
let average = 0;

for (let i = 0; i < data.length; i++) {
average += data[i].adjusted;
let keys = [...new Set([...Object.keys(differences),...Object.keys(data[i].differences)])]
let op = {};

differences = keys.forEach(key=>{
op[key] = {
...differences[key],
...data[i].differences[key]
}
});

differences = op;
}

average /= bot.getCount();

return {adjusted: average, differences: differences};
}

function reducesListLeast(answers, guesses) {
let best_words = [];

Expand Down Expand Up @@ -653,14 +689,3 @@ function findWrongSpotLetters(diff, guess) {
c = [...new Set(c)];
return c;
}

function allInstancesOf(c, string) {
let indices = [];
for (let i = 0; i < string.length; i++) {
if (string.charAt(i) == c) {
indices.push(i);
}
}

return indices;
}
29 changes: 23 additions & 6 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function update() {
let lists = getPotentialGuessesAndAnswers(difficulty);
let best_guesses = [];

if (lists.answers.length > 2 || bot.isFor(ANTI)) {
if (lists.unique.length > 2 || bot.isFor(ANTI)) {
best_guesses = getBestGuesses(lists.answers, lists.guesses, difficulty, lists.unique);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ function getPotentialGuessesAndAnswers(difficulty) {

if (bot.getCount() > 1) {
sorted_guess_list = answerAlreadyFound(sorted_guess_list, answer_list);
answer_list = uniqueWordsFrom(answer_list);
// answer_list = uniqueWordsFrom(answer_list);
}

return {
Expand All @@ -172,7 +172,7 @@ function initialGuesses(answer_list, sorted_answer_list, unique_answers, all_pos

if (bot.isFor(THIRDLE)) sorted_guess_list = allCombinations("", []);

if (answer_list.length <= 2 && !bot.isFor(ANTI)) {
if (twoAnswersLeft(answer_list) && !bot.isFor(ANTI)) {
sorted_guess_list = unique_answers;
} else if (isDifficulty(HARD, difficulty)){
sorted_guess_list = all_possible_words.slice();
Expand All @@ -192,6 +192,14 @@ function initialGuesses(answer_list, sorted_answer_list, unique_answers, all_pos
return sorted_guess_list;
}

function twoAnswersLeft(answers) {
if (bot.getCount() == 1) {
return answers.length <= 2;
}

return uniqueWordsFrom(answers).length <= 2;
}

function answerAlreadyFound(guesses, answer_lists) {
for (let i = 0; i < answer_lists.length; i++) {
if (answer_lists[i].length == 1) {
Expand Down Expand Up @@ -219,6 +227,10 @@ function allCombinations(string, list) {
// adds those suggestions to the respective slides
// creates a dropdown list showing all possible words
function updateLists(words_left, likely_answers, unlikely_answers, best_guesses) {
if (bot.getCount() > 1) {
likely_answers = uniqueWordsFrom(likely_answers);
}

let list_length = Math.min(likely_answers.length, TOP_TEN_LENGTH);
let guess_list = writeBestGuessList(best_guesses, list_length);

Expand Down Expand Up @@ -555,7 +567,12 @@ function getBestGuesses(answer_list, guess_list, difficulty, unique_answers) {
if (guessesSoFar() == bot.guessesAllowed()-1) guess_list = unique_answers;

let initial_guesses = bot.reducesListBest(answer_list, guess_list);
best_guesses = calculateGuessList(unique_answers, guess_list, initial_guesses, difficulty);

if (bot.getCount() > 1) {
best_guesses = initial_guesses;
} else {
best_guesses = calculateGuessList(unique_answers, guess_list, initial_guesses, difficulty);
}

setBestGuesses(best_guesses, difficulty);
return best_guesses;
Expand All @@ -570,10 +587,10 @@ function reduceListSize(guesses, answers, answers_size) {

const MAXIMUM = 100000;
let reduced = false;
if (answers_size * guesses.length > MAXIMUM) {
if (answers_size * guesses.length * bot.getCount() > MAXIMUM) {
guesses = combineLists(answers, guesses);

let current = answers_size * guesses.length;
let current = answers_size * guesses.length * bot.getCount();
let ratio = current/MAXIMUM;

guesses = guesses.slice(0, guesses.length/ratio);
Expand Down

0 comments on commit c83b48b

Please sign in to comment.