mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-16 08:52:42 +00:00
Wordle: prefer common words via DreamDict frequency batch lookup
Gather up to 5 candidate words from DreamDict RandomWord, then use FrequencyBatch to pick the most commonly used one. Players get recognizable everyday words instead of obscure ones that just clear the min_freq floor. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -397,22 +397,23 @@ func (p *WordlePlugin) createAndPostPuzzle(roomID id.RoomID, wordLength int, cat
|
|||||||
return p.SendMessage(roomID, renderWordleStartAnnouncement(puzzleNumber, wordLength, hint))
|
return p.SendMessage(roomID, renderWordleStartAnnouncement(puzzleNumber, wordLength, hint))
|
||||||
}
|
}
|
||||||
|
|
||||||
// pickWord tries DreamDict's RandomWord API first, falling back to the local
|
// pickWord tries DreamDict's RandomWord API first, gathering multiple candidates
|
||||||
// word pool if DreamDict is unavailable or only returns recently-used words.
|
// and selecting the most common one by frequency. Falls back to the local word
|
||||||
|
// pool if DreamDict is unavailable.
|
||||||
func (p *WordlePlugin) pickWord(length int, category WordleCategory) string {
|
func (p *WordlePlugin) pickWord(length int, category WordleCategory) string {
|
||||||
if p.dict != nil {
|
if p.dict != nil {
|
||||||
recent := loadRecentWordleAnswers(500)
|
recent := loadRecentWordleAnswers(500)
|
||||||
lang := categoryLang(category)
|
lang := categoryLang(category)
|
||||||
|
|
||||||
// Try a few times to get a word that hasn't been used recently.
|
// Gather candidate words, then pick the highest-frequency one.
|
||||||
for range 10 {
|
var candidates []string
|
||||||
|
for range 15 {
|
||||||
word, err := p.dict.RandomWord(lang, "", length, length, 500)
|
word, err := p.dict.RandomWord(lang, "", length, length, 500)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("wordle: DreamDict random word failed, falling back", "err", err)
|
slog.Warn("wordle: DreamDict random word failed, falling back", "err", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
word = strings.ToUpper(word)
|
word = strings.ToUpper(word)
|
||||||
// Verify the word is exactly the right length and contains only letters.
|
|
||||||
runes := []rune(word)
|
runes := []rune(word)
|
||||||
if len(runes) != length {
|
if len(runes) != length {
|
||||||
continue
|
continue
|
||||||
@@ -427,9 +428,31 @@ func (p *WordlePlugin) pickWord(length int, category WordleCategory) string {
|
|||||||
if !clean {
|
if !clean {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !recent[word] {
|
if recent[word] {
|
||||||
return word
|
continue
|
||||||
}
|
}
|
||||||
|
candidates = append(candidates, word)
|
||||||
|
if len(candidates) >= 5 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(candidates) > 0 {
|
||||||
|
// Look up frequencies in batch and pick the most common word.
|
||||||
|
freqs, err := p.dict.FrequencyBatch(candidates, lang)
|
||||||
|
if err == nil && len(freqs) > 0 {
|
||||||
|
best := candidates[0]
|
||||||
|
bestFreq := 0
|
||||||
|
for _, w := range candidates {
|
||||||
|
if f, ok := freqs[strings.ToLower(w)]; ok && f > bestFreq {
|
||||||
|
best = w
|
||||||
|
bestFreq = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best
|
||||||
|
}
|
||||||
|
// FrequencyBatch failed — just use the first candidate.
|
||||||
|
return candidates[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user