55 lines
901 B
Go
55 lines
901 B
Go
package game
|
|
|
|
import "tildegit.org/jakew/wordle/game/words"
|
|
|
|
type Guess struct {
|
|
Letters []rune
|
|
Correct []int
|
|
Present []int
|
|
}
|
|
|
|
type Board struct {
|
|
Guesses [6]Guess
|
|
CurrentGuess int
|
|
Solution string
|
|
Done bool
|
|
Day int
|
|
}
|
|
|
|
func NewBoard() *Board {
|
|
solution, day := words.GetSolution()
|
|
return &Board{
|
|
Guesses: [6]Guess{},
|
|
CurrentGuess: 0,
|
|
Solution: solution,
|
|
Day: day,
|
|
}
|
|
}
|
|
|
|
func (b *Board) AddWord(word string) string {
|
|
if b.Done {
|
|
return "You are done!"
|
|
}
|
|
|
|
if len(word) != 5 {
|
|
return "Word must be 5 long!"
|
|
}
|
|
if !words.IsValid(word) {
|
|
return "Word is not in dictionary!"
|
|
}
|
|
|
|
correct, present := words.Check(word, b.Solution)
|
|
b.Guesses[b.CurrentGuess] = Guess{
|
|
Letters: []rune(word),
|
|
Correct: correct,
|
|
Present: present,
|
|
}
|
|
b.CurrentGuess += 1
|
|
|
|
if len(correct) == 5 || b.CurrentGuess >= 6 {
|
|
b.Done = true
|
|
}
|
|
|
|
return ""
|
|
}
|