Skip to content

Commit

Permalink
warmle bot & color coded multibots
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuval Ben-Hayun authored and Yuval Ben-Hayun committed Nov 21, 2022
1 parent ffb092a commit a44bec8
Show file tree
Hide file tree
Showing 6 changed files with 465 additions and 198 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h3 class="mini-header">Choose Your Bot</h3>
<option value="Antiwordle" class = "Antiwordle">Antiwordle</option>
<option value="Xordle" class = "Xordle">Xordle</option>
<option value="Fibble" class = "Fibble">Fibble</option>
<option value="Warmle" class = "Warmle">Warmle</option>
<option value="Hardle" class = "Hardle">Hardle</option>
<option value="Woodle" class = "Woodle">Woodle/Word500</option>
<option value="W-Peaks" class = "W-Peaks">Wordle Peaks</option>
Expand All @@ -83,6 +84,7 @@ <h3 class="mini-header">Choose Your Bot</h3>
<option value="Octordle" class = "Octordle">Octordle</option>
</select>
</p>
<p class="extra-settings"></p>
</div>

<div id="guesses">
Expand All @@ -104,7 +106,6 @@ <h3 class="mini-title"></h3>
<p class="links github">
Do you code? Check out this repo on <a href="https://github.com/ybenhayun" target="_blank">Github</a>.
</p>
<!-- <p class="links"><img src="images/github.png" alt="github link"><img src="images/twitter.png" alt="twitter link"></p> -->
</div>

</body>
Expand Down
8 changes: 4 additions & 4 deletions js/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function swapDiv(event, elem) {
}

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

Expand Down Expand Up @@ -319,7 +319,7 @@ function runBot(guess, difficulty) {
let iv = setInterval(function() {
clearGrids();
let points = wordleBot(guess, testing_sample[count], difficulty);
if (points > bot.guessesAllowed(difficulty)) {
if (points > bot.guessesAllowed()) {
missed.push(testing_sample[count]);
}

Expand Down Expand Up @@ -371,7 +371,7 @@ function updateWordData(guess, average, wrong, difficulty) {
if (TEST_SIZE < common.length) return;

if (!newlist.length) {
if (isDifficulty(HARD, difficulty) && bot.hasHardMode()) newlist = hard;
if (isDifficulty(HARD) && bot.hasHardMode()) newlist = hard;
else newlist = easy;
}

Expand All @@ -397,7 +397,7 @@ function wordleBot(guess, answer, difficulty) {
let attempts = 1;
let correct = 0;

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

let diff;
Expand Down
180 changes: 141 additions & 39 deletions js/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const HARDLE = 'Hardle';
const DORDLE = 'Dordle';
const QUORDLE = 'Quordle';
const OCTORDLE = 'Octordle';
const WARMLE = 'Warmle';


class Bot {
Expand All @@ -22,14 +23,15 @@ class Bot {
}

hasHardMode() {
return this.type == WORDLE || this.type == ANTI;
// return this.type == WORDLE || this.type == ANTI;
return true;
}

hasMax() {
return this.type != ANTI;
}

guessesAllowed(difficulty) {
guessesAllowed() {
if (this.type == ANTI) return INFINITY;
return parseInt(document.getElementById('max-guesses').value);
}
Expand All @@ -45,13 +47,21 @@ class Bot {
getDifference(word1, word2) {
if (this.type == WOODLE) {
return differencesWithoutPositions(word1, word2);
} else if (this.type == PEAKS) {
}

if (this.type == PEAKS) {
return getAlphabeticDifferences(word1, word2);
} else if (typeof word2 == 'object') {
}

if (typeof word2 == 'object') {
return getDoubleDifference(word1, word2);
} else {
return differencesWithPositions(word1, word2);
}

if (this.type == WARMLE) {
return getWarmleDifferences(word1, word2);
}

return differencesWithPositions(word1, word2);
}

getRowColor(row_number) {
Expand All @@ -75,11 +85,15 @@ class Bot {
}

getBestLetters(list) {
if (this.type != PEAKS) {
return mostCommonLetters(list);
} else {
if (this.type == PEAKS) {
return lettersClosestToCenter(list);
}
}

if (this.type == WARMLE) {
return bestWarmleLetters(list);
}

return mostCommonLetters(list);
}

reducesListBest(answers, guesses, future_guess) {
Expand Down Expand Up @@ -138,6 +152,22 @@ class Bot {

return list;
}

getAnswerListLength(answers) {
if (bot.getCount() > 1) {
return lengthOfAllLists(answers);
}

return answers.length;
}

isLikely(answer) {
if (this.type == XORDLE && typeof answer == 'object') {
return this.isLikely(answer.word1) && this.isLikely(answer.word2);
}

return common.includes(answer);
}
}

function isHigher(a, b) {
Expand Down Expand Up @@ -208,13 +238,11 @@ function differencesWithPositions(word1, word2) {

let word1_c = temp1.charAt(j);
if (temp2.includes(word1_c)) {
// diff = diff.slice(0, pos) + WRONG_SPOT + diff.slice(pos+1);
diff = replaceAt(diff, WRONG_SPOT, pos);

let index = temp2.indexOf(word1_c);
temp2 = temp2.slice(0, index) + temp2.slice(index+1);
} else {
// diff = diff.slice(0, pos) + INCORRECT + diff.slice(pos+1);
diff = replaceAt(diff, INCORRECT, pos);
}

Expand Down Expand Up @@ -276,21 +304,6 @@ function rowDifferencesWithPairs(row_number) {
}

return colors;

// let row = document.getElementsByClassName("row");
// let left = row[row_number*2];
// let right = row[row_number*2+1];
// let coloring = "";

// for (let i = 0; i < word_length; i++) {
// coloring += getTileColor(left.getElementsByClassName('tile')[i])
// }

// for (let i = 0; i < word_length; i++) {
// coloring += getTileColor(right.getElementsByClassName('tile')[i])
// }

// return coloring;
}

function getAlphabeticDifferences(word1, word2) {
Expand All @@ -301,9 +314,28 @@ function getAlphabeticDifferences(word1, word2) {
if (a == b) {
diff += CORRECT;
} else if (a > b) {
diff += 'B';
diff += INCORRECT;
} else if (a < b) {
diff += 'Y';
diff += WRONG_SPOT;
}
}

return diff;
}

function getWarmleDifferences(word1, word2) {
let diff = "";
let distance = document.getElementsByClassName('warmle-selector')[0].value;

for (let i = 0; i < word_length; i++) {
let a = word1.charAt(i).charCodeAt(0), b = word2.charAt(i).charCodeAt(0);

if (a == b) {
diff += CORRECT;
} else if (Math.abs(a-b) <= distance ) {
diff += WRONG_SPOT;
} else {
diff += INCORRECT;
}
}

Expand Down Expand Up @@ -413,15 +445,7 @@ function setRowDifferencesWithoutPositions(coloring, row) {
function mostCommonLetters(list) {
if (!list.length) return [];

let letters = [];

for (let c = 65; c <= 90; c++) {
letters[String.fromCharCode(c)] = [];
for (let i = 0; i < parseInt(word_length)+1; i++) {
letters[String.fromCharCode(c)].push(0);
}
}

let letters = makeAlphabetArray(parseInt(word_length)+1);
let checked;

for (let i = 0; i < list.length; i++) {
Expand Down Expand Up @@ -454,6 +478,64 @@ function lettersClosestToCenter() {
return letters;
}

function bestWarmleLetters(list) {
let letters = makeAlphabetArray(parseInt(word_length)+1);

list.forEach(function(word) {
for (let i = 0; i < word_length; i++) {
let c = word.charAt(i);
letters[c][i]++;
letters[c][word.length]++;
}
});

let new_letters = makeAlphabetArray(parseInt(word_length)+1);

for (let i = 65; i <= 90; i++) {
let pos = intToChar(i);

for (let j = 0; j < word_length; j++) {
new_letters[pos][j] = letters[pos][j];

let distance = document.getElementsByClassName('warmle-selector')[0].value;
for (let k = 1; k <= distance; k++) {
let c = charToInt(pos)+k;

if (c <= 90) {
c = intToChar(c);
new_letters[pos][j] += letters[c][j];
}

c = charToInt(pos)-k;
if (c >= 65) {
c = intToChar(c);
new_letters[pos][j] += letters[c][j];
}
}

}

new_letters[pos][word_length] = letters[pos][word_length];
}

return new_letters;
}

function makeAlphabetArray(size) {
let letters = [];

for (let i = 65; i <= 90; i++) {
let c = String.fromCharCode(i);

letters[c] = [];
for (let i = 0; i < size; i++) {
letters[c].push(0);
}
}

return letters;
}

function reducesListMost(answers, guesses, future_guess) {
let best_words = [];
let min = answers.length;
Expand All @@ -465,6 +547,7 @@ function reducesListMost(answers, guesses, future_guess) {
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));
}
Expand Down Expand Up @@ -599,6 +682,10 @@ function getHardleDiffs(diff) {
let differences = [diff];
let new_diff = "";

if (diff == WRONG_SPOT.repeat(word_length)) {
return differences;
}

for (let i = 0; i < diff.length; i++) {
if (diff.charAt(i) == CORRECT) {
new_diff += WRONG_SPOT;
Expand Down Expand Up @@ -672,7 +759,7 @@ function findWrongSpotLetters(diff, guess) {
// find index of every Y character in the differences
let wrong_spots = allInstancesOf(WRONG_SPOT, diff);
let correct = allInstancesOf(CORRECT, diff);
let indices = wrong_spots.concat(correct);
let indices = combineLists(wrong_spots, correct);
let c = [];

// indentify all letters marked as Y
Expand All @@ -683,3 +770,18 @@ function findWrongSpotLetters(diff, guess) {
c = [...new Set(c)];
return c;
}

function lengthOfAllLists(lists) {
if (lists.length && typeof lists[0] == 'string') {
return lists.length;
}

let new_list = [];

lists.forEach(function(a) {
new_list = combineLists(new_list, a);
});

new_list = uniqueWordsFrom(new_list);
return new_list.length;
}
Loading

0 comments on commit a44bec8

Please sign in to comment.