Fixed the main dictionary file
Set the guess limit at 6 Added 7 letter words
This commit is contained in:
parent
947ed37974
commit
1367d99446
8 changed files with 1201 additions and 48 deletions
|
|
@ -5,7 +5,9 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/bitfield/script"
|
||||
gonanoid "github.com/matoous/go-nanoid"
|
||||
"log"
|
||||
"math/rand/v2"
|
||||
|
|
@ -17,6 +19,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const maxWordLength = 7
|
||||
|
||||
var validWordRegex = regexp.MustCompile(`^[a-z]+$`)
|
||||
|
||||
type wordList struct {
|
||||
|
|
@ -46,7 +50,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
if len(w) >= 4 && len(w) <= 6 {
|
||||
if len(w) >= 4 && len(w) <= maxWordLength {
|
||||
wordSet[word] = true
|
||||
}
|
||||
}); err != nil {
|
||||
|
|
@ -81,7 +85,7 @@ func main() {
|
|||
pattern[i] = i
|
||||
}
|
||||
|
||||
for x := 4; x < r.IntN(8)+4; x++ {
|
||||
for x := 12; x < r.IntN(8)+16; x++ {
|
||||
r.Shuffle(len(pattern), func(i, j int) {
|
||||
pattern[i], pattern[j] = pattern[j], pattern[i]
|
||||
})
|
||||
|
|
@ -109,7 +113,7 @@ func scanSuitableWords(dictDir string, withWord func(word string)) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := scanSuitableWordsFromEnGB(filepath.Join(dictDir, "en_GB.dic"), withWord); err != nil {
|
||||
if err := scanSuitableWordsFromEnGB(filepath.Join(dictDir, "en_GB.dic"), filepath.Join(dictDir, "en_GB.aff"), withWord); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -149,35 +153,14 @@ func scanSuitableWordsFromOxford3000(dictFile string, withWord func(word string)
|
|||
return scanner.Err()
|
||||
}
|
||||
|
||||
func scanSuitableWordsFromEnGB(dictFile string, withWord func(word string)) error {
|
||||
f, err := os.Open(dictFile)
|
||||
func scanSuitableWordsFromEnGB(dictFile, affFile string, withWord func(word string)) error {
|
||||
words, err := script.Exec(fmt.Sprintf("unmunch '%v' '%v'", dictFile, affFile)).String()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
isSuitable := true
|
||||
breakpoint := len(scanner.Text())
|
||||
|
||||
for i, r := range scanner.Text() {
|
||||
if r == '/' {
|
||||
breakpoint = i
|
||||
break
|
||||
}
|
||||
|
||||
if r < 'a' || r > 'z' {
|
||||
isSuitable = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isSuitable {
|
||||
word := scanner.Text()[:breakpoint]
|
||||
withWord(word)
|
||||
} else {
|
||||
}
|
||||
for _, word := range strings.Split(words, "\n") {
|
||||
withWord(word)
|
||||
}
|
||||
return scanner.Err()
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue