Skip to content

Commit

Permalink
Plays a random word if none selected.
Browse files Browse the repository at this point in the history
  • Loading branch information
archy-bold committed Jan 5, 2022
1 parent 7551752 commit e7dcd26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"bufio"
"flag"
"fmt"
"math/rand"
"os"
"sort"
"strconv"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -35,14 +37,26 @@ var answersIncorrectAll []string
var board []string

func main() {
wordPtr := flag.String("word", "tapir", "The game's answer")
wordPtr := flag.String("word", "", "The game's answer")
playPtr := flag.Bool("play", false, "Whether to play the game")
flag.Parse()

// Read the valid words
fmt.Println("Reading words...")
err := readValidWords()
fmt.Printf("Found %d\n", len(validWords))
check(err)

reader := bufio.NewReader(os.Stdin)

if *playPtr {
g := CreateGame(*wordPtr, NUM_ATTEMPTS)
// If no answer given in the word flag, choose
answer := *wordPtr
if answer == "" {
rand.Seed(time.Now().Unix())
answer = validWords[rand.Intn(len(validWords))]
}
g := CreateGame(answer, NUM_ATTEMPTS)

for {
fmt.Print("Enter your guess: ")
Expand All @@ -64,11 +78,6 @@ func main() {
}
}

// Read the valid words
fmt.Println("Reading words...")
err := readValidWords()
check(err)

answersCorrect = make([]string, NUM_LETTERS)
answersIncorrect = make([][]string, NUM_LETTERS)

Expand Down
Binary file modified wordle
Binary file not shown.

0 comments on commit e7dcd26

Please sign in to comment.