Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
096e2f50fc | |||
846a0575da |
@ -14,8 +14,11 @@ go build .
|
||||
## Running instructions
|
||||
|
||||
```bash
|
||||
% ./gordle --help
|
||||
% ./gordle --help
|
||||
|
||||
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
|
||||
Word size (default 5)
|
||||
```
|
||||
@ -28,4 +31,4 @@ go test # [-cover]
|
||||
|
||||
## 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
|
||||
|
14
gordle.go
14
gordle.go
@ -26,13 +26,17 @@ func main() {
|
||||
containsOutput := color.New(color.BgYellow, 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()
|
||||
nChar := *nFlag
|
||||
|
||||
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 {
|
||||
log.Fatal("There is no dictionary with such amount of letters")
|
||||
@ -48,6 +52,10 @@ func main() {
|
||||
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))
|
||||
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
Loading…
x
Reference in New Issue
Block a user