From 379a8845a1a90b3b86c8d478ee97c86bea8902e9 Mon Sep 17 00:00:00 2001 From: Lukas Schwab Date: Wed, 7 Jan 2026 19:24:49 +0000 Subject: [PATCH] add --save flag and enhance .boggle file metadata Co-Authored-By: sketch Change-ID: s079943df500374b8k --- README.md | 5 +++-- main.go | 23 ++++++++++++++--------- pkg/game/file.go | 9 ++++++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 89b2d67..fb087f0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/main.go b/main.go index a059e4d..3d8cfd6 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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() { @@ -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 { diff --git a/pkg/game/file.go b/pkg/game/file.go index 8b6e4f2..338873a 100644 --- a/pkg/game/file.go +++ b/pkg/game/file.go @@ -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