Title: | The 'WORDLE' Game |
---|---|
Description: | The 'Wordle' game. Players have six attempts to guess a five-letter word. After each guess, the player is informed which letters in their guess are either: anywhere in the word; in the right position in the word. This can be used to inform the next guess. Can be played interactively in the console, or programmatically. Based on Josh Wardle's game <https://www.powerlanguage.co.uk/wordle/>. |
Authors: | David Smith [aut, cre], Gethin Davies [ctb] |
Maintainer: | David Smith <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.1.9001 |
Built: | 2024-11-10 05:15:19 UTC |
Source: | https://github.com/davidasmith/wordler |
Assesses the guess in list game$guess
(index from
game$guess_count
) against the target word in game$target
.
assess_guess(game)
assess_guess(game)
game |
'wordler' game object (as generated by
|
Adds the assessment to the corresponding list item in game$assess
.
This assessment should be considered as how the guesses should be displayed
to the user and replicates the behaviour of the WORDLE game
(https://www.powerlanguage.co.uk/wordle/).
For each letter in each guess, one of the following assessments are made:
'not_in_word' - the letter is not present in the target word (or has already been flagged as 'in_word' earlier in the word).
'in_word' - the letter is in the target word. More specifically, the first instance of the letter in the guess present in the word. Subsequent instances are flagged as 'not_in_word'.
'in_position' - the letter is in the same position in the target word.
'wordler' game object.
Check if current guess complies with hard_mode rules
check_guess_hard_mode(guess, game)
check_guess_hard_mode(guess, game)
guess |
The guess |
game |
Wordler game object. |
bool
If x
is a valid guess, it is added to game$guess
and assessed
against the target word. Increments game$guess_count if a valid guess is made.
have_a_guess(x, game, allowed_words = NULL)
have_a_guess(x, game, allowed_words = NULL)
x |
the guess. |
game |
'wordler' game object (as generated by
|
allowed_words |
a character vector of valid words for the guess. x must be in this vector to be allowed. Defaults to words used by the WORDLE game online (?wordler::wordle_allowed) if not provided. |
A 'wordler' game object.
Compares the guess in game$guess
(index from game$guess_count
)
with the corresponding target word in game$target
. If the guess is
equal to the target, game$game_won
and game$game_over
are
both set to TRUE
.
is_guess_correct(game)
is_guess_correct(game)
game |
'wordler' game object (as generated by
|
A 'wordler' game object.
Detects wordler objects
is.wordler(x, ...)
is.wordler(x, ...)
x |
an R object |
... |
additional arguments |
Returns TRUE
if x is a 'wordler' object, otherwise
FALSE
.
A list of keyboard layouts used to show letters known to be not in target word, in the target word, and in the right position in the target word. Each element must be a list having 3 items, each representing a row of a keyboard layout.
keyboards
keyboards
A list of length 1.
https://gist.github.com/cfreshman/cdcdf777450c5b5301e439061d29694c
Returns a "wordler" object which holds the state of a wordler game as
guesses are made. The returned object will have a target word which is
selected from the default list unless provided in the target
argument.
new_wordler( target = sample(wordler::wordle_answers, 1), game_over = FALSE, game_won = FALSE, guess_count = 0, guess = lapply(1:6, function(x) unlist(strsplit("_____", ""))), assess = lapply(1:6, function(x) rep("not_in_word", 5)), keyboard = wordler::keyboards$qwerty, letters_known_not_in_word = character(0), letters_known_in_word = character(0), letters_known_in_position = character(0), hard_mode = FALSE )
new_wordler( target = sample(wordler::wordle_answers, 1), game_over = FALSE, game_won = FALSE, guess_count = 0, guess = lapply(1:6, function(x) unlist(strsplit("_____", ""))), assess = lapply(1:6, function(x) rep("not_in_word", 5)), keyboard = wordler::keyboards$qwerty, letters_known_not_in_word = character(0), letters_known_in_word = character(0), letters_known_in_position = character(0), hard_mode = FALSE )
target |
the target word for the game. Defaults to a random selection from words used by the WORDLE game online (?wordler::wordle_answers) if not provided. |
game_over |
a logical indicating if the game is over. Defaults to FALSE. |
game_won |
a logical indicating if the game has been won. In other words, has the target word been correctly guessed. |
guess_count |
an integer representing the number of guesses made so far. Defaults to 0. |
guess |
a list (of length 6) of character vectors (each of length 5)
representing the guesses of the target word. Each element of the list
represents one of six guesses allowed. Each guess defaults to
|
assess |
a list (of length 6) of character vectors (each of length 5) representing an assessment of each letter in each guess. |
keyboard |
a list (of length 3) of character vectors each representing
a row of a keyboard layout used to visualise the game by |
letters_known_not_in_word |
a character vector of letters known not to be in the target word. |
letters_known_in_word |
a character vector of letters know to be in the target word. |
letters_known_in_position |
a character vector of letters known to be in the correct position in the target word. |
hard_mode |
Flag if game is in hard mode |
The wordler object is a list which has the following elements:
target
- The target word.
game_over
- A logical indicating if the game is over. Set to
TRUE
if either the word is correctly guessed, or all guesses are
used.
game_won
- A logical indicating if the game has been won
(target word correctly guessed).
guess_count
- The number of guesses made so far.
guess
- A list of guesses of the target word.
assess
- A list of assessments of the target word. Note that
this represents how the letters in each guess should be displayed when
printing the game.
keyboard
- A list representing the keyboard layout to be used
when printing the game state.
letters_known_not_in_word
- A vector of letters known not to
be in the target word based on guesses made so far.
letters_known_in_word
- A vector of letters known to
be in the target word based on guesses made so far.
letters_known_not_in_word
- A vector of letters known to
be in the right position in the target word based on guesses made so far.
hard_mode
- A logical indicating if the game is being played
in hard_mode. In hard mode any revealed hints must be used in subsequent
guesses
An object of class "wordler".
Starts an interactive game of WORDLE in the console. Based on WORDLE (https://www.powerlanguage.co.uk/wordle/).
play_wordler(target_words = NULL, allowed_words = NULL, hard_mode = FALSE)
play_wordler(target_words = NULL, allowed_words = NULL, hard_mode = FALSE)
target_words |
character vector of potential target words for the game. A word will be randomly selected from this vector as the target word to be guessed. Defaults to words used by the WORDLE game online (?wordler::wordle_answers) if not provided. |
allowed_words |
character vector of valid words for the guess. Guess must be in this vector to be allowed. Defaults to words used by the WORDLE game online (?wordler::wordle_allowed) if not provided. |
hard_mode |
logical flag indicating if hard mode should be used. In hard mode any revealed hints must be used in subsequent guesses |
No return value. Starts interactive game in console.
Prints instructions to play a wordler game in the console
print_instructions()
print_instructions()
No return value.
Prints a wordler game to the console.
## S3 method for class 'wordler' print(x, ...)
## S3 method for class 'wordler' print(x, ...)
x |
'wordler' game object (as generated by
|
... |
additional arguments |
No return value.
A dataset containing all five-letter words from the Nettalk Corpus Syllable Data Set as returned by qdapDictionaries::dictionaries().
qdap_dict
qdap_dict
A character vector of length 2488.
https://CRAN.R-project.org/package=qdapDictionaries/
A dataset containing all five-letter words from Ubuntu dictionary '/usr/share/dict/words'.
ubuntu_dict
ubuntu_dict
A character vector of length 4594.
For all items in game$guess
, establishes the letters which are now
known to be in the correct position in the target word. These are present as
a character vector in game$letters_known_in_position
in the returned
object.
update_letters_known_in_position(game)
update_letters_known_in_position(game)
game |
'wordler' game object (as generated by
|
A 'wordler' game object.
For all items in game$guess
, establishes the letters which are now
known to be in the target word. These are present as a character vector in
game$letters_known_in_word
in the returned object.
update_letters_known_in_word(game)
update_letters_known_in_word(game)
game |
'wordler' game object (as generated by
|
A 'wordler' game object.
For all items in game$guess
, establishes the letters which are now
known to not be in the target word. These are present as a character vector
in game$letters_known_not_in_word
in the returned object.
update_letters_known_not_in_word(game)
update_letters_known_not_in_word(game)
game |
'wordler' game object (as generated by
|
A 'wordler' game object.
A dataset containing all words which are used to validate guesses by the original WORDLE game. Note that this does not include the words which can be answers. Theses are held in ?wordle_answers.
wordle_allowed
wordle_allowed
A character vector of length 10657.
https://gist.github.com/cfreshman/cdcdf777450c5b5301e439061d29694c
A dataset containing all words which can be used as answers to the original WORDLE game.
wordle_answers
wordle_answers
A character vector of length 2315.
https://gist.github.com/cfreshman/a03ef2cba789d8cf00c08f767e0fad7b/