HomeProjectsContactGitHub

Wordle Bot

Repository

A high-performance Wordle CLI with included solver. Analyze letter frequencies, simulate weighted strategies, and optimize the solver with a customizable heuristic engine.

Main Solver Loop

This is the main loop inside the solver program. It asks you for the word you picked and prompts you to enter your pattern for the letters (c: correct letter, m: misplaced letter, w: wrong letter) before moving on to the filtering and ranking process. After that, the top 10 best-ranking words get printed out to the terminal.

1// Step 1: enter word
2print!("Enter your 5-letter guess (or 'exit'): ");
3io::stdout().flush()?;
4let mut word = String::new();
5io::stdin().read_line(&mut word)?;
6let word = word.trim().to_lowercase();
7
8if word == "exit" {
9    println!("Exiting solver.");
10    break;
11}
12
13if word == "-r" {
14    self.reset()?;
15    println!("Solver has been reset.\n");
16    continue; // skip the rest of the loop entirely
17}
18
19if word.len() != 5 {
20    println!("Please enter a 5-letter word.\n");
21    continue;
22}
23
24// Check if guess exists in wordlist (uses preloaded all_words)
25if !self.all_words.contains(&word) {
26    println!("'{}' is not in the wordlist.\n", word);
27    continue;
28}
29
30// Step 2: enter pattern
31print!("Enter pattern (w = wrong, m = misplaced, c = correct): ");
32io::stdout().flush()?;
33let mut pattern = String::new();
34io::stdin().read_line(&mut pattern)?;
35let pattern = pattern.trim().to_lowercase();
36
37if pattern.len() != 5 || !pattern.chars().all(|c| "wmc".contains(c)) {
38    println!("Invalid pattern. Use only w, m, c.\n");
39    continue;
40}

Filtering the Words

Filtering the words is the core part of the Wordle solver. This is a snippet from my "filter.rs" script. It works by filtering out the words that, for example, don't contain the letters given by the first try.

1fn not_strictly_forbidden(&self, chars: &[char]) -> bool {
2    for ch in chars {
3        if self.game.contains_not.contains(ch) && !self.game.must_contain.contains(ch) {
4            return false;
5        }
6    }
7    true
8}
9
10fn matches_correct_positions(&self, chars: &[char]) -> bool {
11    for (i, maybe_correct) in self.game.correct_positions.iter().enumerate() {
12        if let Some(expected) = maybe_correct {
13            if chars[i] != *expected {
14                return false;
15            }
16        }
17    }
18    true
19}
20
21fn respects_misplaced_constraints(&self, chars: &[char]) -> bool {
22    for (pos, letters) in &self.game.misplaced_letters {
23        for &letter in letters {
24            if chars[*pos] == letter {
25                return false;
26            }
27            if !chars.contains(&letter) {
28                return false;
29            }
30        }
31    }
32    true
33}
34
35fn contains_required_letters(&self, chars: &[char]) -> bool {
36    let present: HashSet<char> = chars.iter().copied().collect();
37    for &req in &self.game.must_contain {
38        if !present.contains(&req) {
39            return false;
40        }
41    }
42    true
43}

Playing Wordle

With this program, you can directly play Wordle inside your terminal as well! This snippet prints a summary of your current game with the famous Wordle keyboard as well.

1fn print_summary(&self) {
2    println!("\n=== Current Game State ===");
3    println!("Nr.  Word");
4
5    for (number, line) in self.game_data.lines.iter().enumerate() {
6        print!("{}.   ", number + 1);
7
8        for cell in &line.cells {
9            let letter = cell.letter.to_ascii_uppercase();
10
11            let color = match cell.state {
12                'c' => "\x1b[42m\x1b[30m",  // green background, black text
13                'm' => "\x1b[43m\x1b[30m",  // yellow background, black text
14                'w' => "\x1b[100m\x1b[37m", // gray background, white text
15                _ => "\x1b[0m",
16            };
17
18            print!("{} {} \x1b[0m", color, letter);
19        }
20        println!();
21    }
22    println!("==========================\n");
23    println!("{}", self.generate_keyboard());
24}

Try it out yourself!

Download

To run the bot from your terminal (Command Prompt or PowerShell), navigate to the folder where you downloaded the file and type: wordle-bot.exe