knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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.
First, load the package.
library(wordler)
To play a game in the console, call the play_wordler()
function.
# Commented out so vignette can be generated #play_wordler()
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.
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))
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
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
The number of guesses made so far is held in the guess_count
item.
game$guess_count
The word we're trying to guess is held in the target
item.
game$target
The list of guesses so far is available in the guess
item.
game$guess
The assess
item is a list holding the assessments of each guess.
game$assess
At any time, we can print the status of the game as follows.
print(game)
A vector of letters known to not be in the target word is available.
game$letters_known_not_in_word
A vector of letters known to be in the target word is available.
game$letters_known_in_word
A vector of letters known to be in the right position in the target word is available.
game$letters_known_in_position
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.