Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ boggle - play an unsanctioned game of boggle.
This game uses the Collins Scrabble Words 2019 dictionary, a three-minute timer,
and requires words be at least four letters long.

Each game outputs a .boggle file describing the board and your performance. You
can replay a board by passing a .boggle file to this program:
You can replay a board by passing a .boggle file to this program:

$ boggle -file past-game.boggle

Expand All @@ -39,6 +38,8 @@ The following options are available:
-new
use the "New" Boggle dice set (since 2008).
See: https://www.bananagrammer.com/2013/10/the-boggle-cube-redesign-and-its-effect.html
-save
save game results to a .boggle file
-skip
skip interactive game
-solve
Expand Down
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const usage = `boggle - play an unsanctioned game of boggle.
This game uses the Collins Scrabble Words 2019 dictionary, a three-minute timer,
and requires words be at least four letters long.

Each game outputs a .boggle file describing the board and your performance. You
can replay a board by passing a .boggle file to this program:
You can replay a board by passing a .boggle file to this program:

$ boggle -file past-game.boggle

Expand All @@ -37,6 +36,7 @@ func main() {
var boardUrlFlag = flag.String("url", "", "web URL of a public .boggle file to configure game")
var solveFlag = flag.Bool("solve", false, "print all possible words on board after game")
var skipFlag = flag.Bool("skip", false, "skip interactive game")
var saveFlag = flag.Bool("save", false, "save game results to a .boggle file")
var newFlag = flag.Bool("new", false, "use the \"New\" Boggle dice set (since 2008).\nSee: https://www.bananagrammer.com/2013/10/the-boggle-cube-redesign-and-its-effect.html")

flag.Usage = func() {
Expand Down Expand Up @@ -98,14 +98,19 @@ func main() {
log.Fatal(err.Error())
}

filename := fmt.Sprintf("./%s.boggle", time.Now().UTC().Format(time.RFC3339))
if err := game.WriteFile(filename, game.Frontmatter{
Board: b.Serialize(),
TimerSeconds: 180,
}, words); err != nil {
log.Fatal(err.Error())
if *saveFlag {
filename := fmt.Sprintf("./%s.boggle", time.Now().UTC().Format(time.RFC3339))
if err := game.WriteFile(filename, game.Frontmatter{
Board: b.Serialize(),
TimerSeconds: 180,
WordsFound: len(words),
TotalAvailableWords: len(boardWordsDict.Members()),
Dictionary: "Collins Scrabble Words 2019",
}, words); err != nil {
log.Fatal(err.Error())
}
log.Infof("Wrote %v", filename)
}
log.Infof("Wrote %v", filename)
}

if *solveFlag {
Expand Down
9 changes: 6 additions & 3 deletions pkg/game/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ func LoadFile(path string) (f Frontmatter, words []string, err error) {

type Frontmatter struct {
// Board, serialized; see [boggle.Deserialize].
Board string
TimerSeconds int
AboutThisFile string
Board string
TimerSeconds int
WordsFound int
TotalAvailableWords int
Dictionary string
AboutThisFile string
}

//nolint:errcheck
Expand Down
Loading