Introduction to wordler

This package lets you play a version of the WORDLE game in R. You can either play interactively in the console, or programmatically to explore different solvers (for example).

Players must attempt to correctly guess a five-letter word in (at most) six attempts.

After each guess, the letters are coloured to indicate how well the guess matches the target word.

Green letters are in the word and in the right position (but may be repeated elsewhere). Yellow letters are present (at least once) somewhere in the target word.

Each guess must be a valid word.

Load the package

First, load the package.

library(wordler)

Playing a game in the console

To play a game in the console, call the play_wordler() function.

# Commented out so vignette can be generated
#play_wordler()

Playing a game programmatically

Initialise a new game

First, initialise a new game.

game <- new_wordler()

This returns a list which represents the game state. We’ll have a look at the items in this list after we’ve made a few guesses.

Make a guess

Use have_a_guess() to submit a guess of the target word. We’ll make a few guesses below.

game <- have_a_guess("SQUID", game, allowed_words = c(wordle_answers, wordle_allowed))
game <- have_a_guess("VIDEO", game, allowed_words = c(wordle_answers, wordle_allowed))

The allowed_words argument is a character vector used to validate the guesses. The guess must be present in this vector to be permitted. If the guess is not in allowed_words, a message is displayed and you can have another go.

game <- have_a_guess("DONKY", game, allowed_words = c(wordle_answers, wordle_allowed))
#> Your word isn't in the list of valid words. Try again.

Game state

Now let’s look what’s happening in the game object.

We have an item which represents whether the game is over, or still in play.

game$game_over
#> [1] FALSE

This is set to TRUE if either the word is correctly guessed, or all guesses are used.

The game_won item indicates if the target word has been guessed correctly.

game$game_won
#> [1] FALSE

The number of guesses made so far is held in the guess_count item.

game$guess_count
#> [1] 2

The word we’re trying to guess is held in the target item.

game$target
#> [1] "EVERY"

The list of guesses so far is available in the guess item.

game$guess
#> [[1]]
#> [1] "S" "Q" "U" "I" "D"
#> 
#> [[2]]
#> [1] "V" "I" "D" "E" "O"
#> 
#> [[3]]
#> [1] "_" "_" "_" "_" "_"
#> 
#> [[4]]
#> [1] "_" "_" "_" "_" "_"
#> 
#> [[5]]
#> [1] "_" "_" "_" "_" "_"
#> 
#> [[6]]
#> [1] "_" "_" "_" "_" "_"

The assess item is a list holding the assessments of each guess.

game$assess
#> [[1]]
#> [1] "not_in_word" "not_in_word" "not_in_word" "not_in_word" "not_in_word"
#> 
#> [[2]]
#> [1] "in_word"     "not_in_word" "not_in_word" "in_word"     "not_in_word"
#> 
#> [[3]]
#> [1] "not_in_word" "not_in_word" "not_in_word" "not_in_word" "not_in_word"
#> 
#> [[4]]
#> [1] "not_in_word" "not_in_word" "not_in_word" "not_in_word" "not_in_word"
#> 
#> [[5]]
#> [1] "not_in_word" "not_in_word" "not_in_word" "not_in_word" "not_in_word"
#> 
#> [[6]]
#> [1] "not_in_word" "not_in_word" "not_in_word" "not_in_word" "not_in_word"

At any time, we can print the status of the game as follows.

print(game)
#> 
#>     S Q U I D 
#>     V I D E O         W  E  R  T  Y           P  
#>     _ _ _ _ _        A        F  G  H  J  K  L  
#>     _ _ _ _ _          Z  X  C  V  B  N  M  
#>     _ _ _ _ _ 
#>     _ _ _ _ _

A vector of letters known to not be in the target word is available.

game$letters_known_not_in_word
#> [1] "S" "Q" "U" "I" "D" "O"

A vector of letters known to be in the target word is available.

game$letters_known_in_word
#> [1] "V" "E"

A vector of letters known to be in the right position in the target word is available.

game$letters_known_in_position
#> character(0)