Compare commits

...

2 Commits
v0.1.0 ... main

Author SHA1 Message Date
096e2f50fc Updated readme 2022-07-17 18:42:14 +03:00
846a0575da Added custom dictionary path support 2022-07-08 03:51:34 +03:00
2 changed files with 16 additions and 5 deletions

View File

@ -15,7 +15,10 @@ go build .
```bash ```bash
% ./gordle --help % ./gordle --help
Usage of ./gordle: Usage of ./gordle:
-f string
Path to dictionary file with words of length -n. If specified, -n must be specified too (if the latter must not be equal to default value (default "./dictionary/5.txt")
-n int -n int
Word size (default 5) Word size (default 5)
``` ```
@ -28,4 +31,4 @@ go test # [-cover]
## Dictionaries ## Dictionaries
To run game you also need dictionary files. By default gordle searches for them in `./dictionary/<n>.txt` file, where `<n>` - number of characters, specified by `-n` flag To run game you also need dictionary files. By default gordle searches for them in `./dictionary/<n>.txt` file, where `<n>` - number of characters, specified by `-n` flag. If want to use custom one, provide in `-f` flag path to txt file with strings separated by new line characters

View File

@ -26,13 +26,17 @@ func main() {
containsOutput := color.New(color.BgYellow, color.FgBlack) containsOutput := color.New(color.BgYellow, color.FgBlack)
wrongOutput := color.New(color.BgWhite, color.FgBlack) wrongOutput := color.New(color.BgWhite, color.FgBlack)
var nFlag = flag.Int("n", 5, "Word size") nFlag := flag.Int("n", 5, "Word size")
fFlag := flag.String("f", "./dictionary/5.txt", "Path to dictionary file with words of length -n. If specified, -n must be specified too (if the latter must not be equal to default value")
flag.Parse() flag.Parse()
nChar := *nFlag
fmt.Println("Welcome to Gordle - go implementation of Wordle game") fmt.Println("Welcome to Gordle - go implementation of Wordle game")
file, err := os.Open(fmt.Sprintf("./dictionary/%d.txt", nChar)) nChar := *nFlag
filePath := *fFlag
file, err := os.Open(filePath)
if err != nil { if err != nil {
log.Fatal("There is no dictionary with such amount of letters") log.Fatal("There is no dictionary with such amount of letters")
@ -48,6 +52,10 @@ func main() {
words = append(words, scanner.Text()) words = append(words, scanner.Text())
} }
if len(words[0]) != nChar {
log.Fatal("Words in dictionary must be of size", nChar)
}
fmt.Printf("You are going to guess a %d letter word in %d tries from %d dictionary\n", nChar, nChar+1, len(words)) fmt.Printf("You are going to guess a %d letter word in %d tries from %d dictionary\n", nChar, nChar+1, len(words))
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())