Wordlegames.jl
A Julia package to play and analyze Wordle
and Wordle-like games.
Wordlegames.GameNode
— TypeGameNode
Node type for tree representing game play on a GamePool{N}
Fields are:
score
: aGameScore
for this target based on the score that generated the nodechildren
:Vector{GameNode}
of children of this node
Wordlegames.GamePool
— TypeGamePool{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
: aVector{NTuple{N,Char}}
of potential guessesvalidtargets
: aBitVector
of valid targets in theguesspool
allscores
: a cache of pre-computed scores as aMatrix{S}
of size(sum(validtargets), length(guesspool))
active
:BitVector
of lengthsum(validtargets)
. The active pool of targets isguesspool[validtargets][active]
.counts
:Vector{Int}
of length3 ^ N
in which bin counts are accumulatedguesses
:Vector{GuessScore}
recording game playhardmode
: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)
Wordlegames.GuessScore
— TypeGuessScore
A NamedTuple
for recording a guess and its score, when available.
Wordlegames.bincounts!
— Functionbincounts!(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]
.
Wordlegames.entropy2
— Functionentropy2(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.
Wordlegames.expectedpoolsize
— Functionexpectedpoolsize(gp::GamePool)
Return the expected pool size from gp.counts
.
Wordlegames.hasdups
— Functionhasdups(guess::NTuple{N,Char}) where {N}
Returns true
if there are duplicate characters in guess
.
Wordlegames.optimalguess
— Functionoptimalguess(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
Wordlegames.playgame!
— Functionplaygame!(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!
Wordlegames.reset!
— Functionreset!(gp::GamePool)
Return gp
with its active
, guess
, and entropy
fields reset to initial values.
Wordlegames.scorecolumn!
— Functionscorecolumn!(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.
Wordlegames.scoreupdate!
— Functionscoreupdate!(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)
.
Wordlegames.showgame!
— Functionshowgame!(gp::GamePool[, target])
Return a Tables.ColumnTable
of playgame!(gp, target)))
.
Wordlegames.tiles
— Functiontiles(score::Integer, ntiles::Integer)
tiles(svec::AbstractVector{<:Integer})
Return a length-ntiles
String
tile pattern from the numeric score score
.
Wordlegames.tree
— Functiontree(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.
Wordlegames.updateguess!
— Functionupdateguess!(gp::GamePool)
Choose the optimal guess the GuessType
of gp
and push! a new tuple onto gp.guesses
.
Wordlegames.GameNode
Wordlegames.GamePool
Wordlegames.GuessScore
Wordlegames.bincounts!
Wordlegames.entropy2
Wordlegames.expectedpoolsize
Wordlegames.hasdups
Wordlegames.optimalguess
Wordlegames.playgame!
Wordlegames.reset!
Wordlegames.scorecolumn!
Wordlegames.scoreupdate!
Wordlegames.showgame!
Wordlegames.tiles
Wordlegames.tree
Wordlegames.updateguess!