Wordlegames.jl

A Julia package to play and analyze Wordle and Wordle-like games.

Wordlegames.GameNodeType
GameNode

Node type for tree representing game play on a GamePool{N}

Fields are:

  • score: a GameScore for this target based on the score that generated the node
  • children: Vector{GameNode} of children of this node
source
Wordlegames.GamePoolType
GamePool{N,S,G}

A struct that defines a Wordle-like game with targets of length N. S <: Unsigned is the smallest unsigned integer type that can store values in the range 0:(3 ^ N - 1) (obtained as Wordlegames.scoretype(N)) and G <: GuessType is the guess type, which defaults to MaximizeEntropy.

The fields are:

  • guesspool: a Vector{NTuple{N,Char}} of potential guesses
  • validtargets: a BitVector of valid targets in the guesspool
  • allscores: a cache of pre-computed scores as a Matrix{S} of size (sum(validtargets), length(guesspool))
  • active: BitVector of length sum(validtargets). The active pool of targets is guesspool[validtargets][active].
  • counts: Vector{Int} of length 3 ^ N in which bin counts are accumulated
  • guesses: Vector{GuessScore} recording game play
  • hardmode: Bool - should the game be played in "Hard Mode"?

Constructor signatures include

GamePool(guesspool::Vector{NTuple{N,Char}}, validtargets::BitVector; guesstype=MaximizeEntropy, hardmode::Bool=true) where {N}
GamePool(guesspool::Vector{NTuple{N,Char}}; guesstype=MaximizeEntropy, hardmode::Bool=true) where {N}
GamePool(guesspool::AbstractVector{<:AbstractString}; guesstype=MaximizeEntropy, hardmode::Bool=true)
GamePool(guesspool::AbstractVector; guesstype=MaximizeEntropy, hardmode::Bool=true)
source
Wordlegames.bincounts!Function
bincounts!(counts, active, scorevec)
bincounts!(gp::GamePool, k)

Return counts overwritten with bin probabilities from scorevec[active] or update gp.counts from gp.active and gp.allscores[:,k].

source
Wordlegames.entropy2Function
entropy2(counts::AbstractVector{<:Real})
entropy2(gp::GamePool)

Return the base-2 entropy of counts or gp.counts, converted to probabilities.

The result is the entropy measured in bits. See the Wikipedia entry for the definition of entropy in information theory.

source
Wordlegames.hasdupsFunction
hasdups(guess::NTuple{N,Char}) where {N}

Returns true if there are duplicate characters in guess.

source
Wordlegames.optimalguessFunction
optimalguess(gp::GamePool{N,S,G}) where {N,S,G}

Return the optimal guess as a Tuple{Int,Float64,Float64} from view(gp.guesspool, gp.active) according to strategy G

source
Wordlegames.playgame!Function
playgame!(gp::GamePool, ind::Integer)
playgame!(gp::GamePool[, rng::AbstractRNG])
playgame!(gp::GamePool{N}, target::NTuple{N,Char}) where {N}
playgame!(gp::GamePool{N}, target::AbstractString) where {N}

Return gp after playing a game with target gp.targetpool[ind], or a randomly chosen target or target given as an AbstractString or NTuple{N,Char}.

A target as a string must have length(target) == N.

See also: showgame!

source
Wordlegames.reset!Function
reset!(gp::GamePool)

Return gp with its active, guess, and entropy fields reset to initial values.

source
Wordlegames.scorecolumn!Function
scorecolumn!(col, guess::NTuple{N,Char}, targets::AbstractVector{NTuple{N,Char}})

Return col updated with the scores of guess on each of the elements of targets

If there are no duplicate characters in guess a simple algorithm is used, otherwise the more complex algorithm that accounts for duplicates is used.

source
Wordlegames.scoreupdate!Function
scoreupdate!(gp::GamePool, sc::Integer)
scoreupdate!(gp::GamePool{N}, scv::Vector{<:Integer}) where {N}

Update gp with the score sc, or a vector scv of length N whose elements are 0, 1, or 2 for last(gp.guesses)

Always push!(gp.scores, sc). If sc is the maximum possible score, 3 ^ N - 1, the game is over and return gp. Otherwise, update gp.active and call updateguess!(gp).

source
Wordlegames.tilesFunction
tiles(score::Integer, ntiles::Integer)
tiles(svec::AbstractVector{<:Integer})

Return a length-ntiles String tile pattern from the numeric score score.

source
Wordlegames.treeFunction
tree(gp::GamePool, inds::AbstractVector{<:Integer})
tree(gp::GamePool{N}, targets::AbstractVector{NTuple{N,Char}})
tree(gp::GamePool, targets::AbstractVector{<:AbstractString})
tree(gp::GamePool)

Return the root GameNode of a tree of the result of playgame!.(Ref(gp), inds)

A print_tree method is available for this tree.

source
Wordlegames.updateguess!Function
updateguess!(gp::GamePool)

Choose the optimal guess the GuessType of gp and push! a new tuple onto gp.guesses.

source