diff --git a/cli/commands/play.go b/cli/commands/play.go index 32209f9..5456cfa 100644 --- a/cli/commands/play.go +++ b/cli/commands/play.go @@ -27,15 +27,7 @@ import ( log "github.com/spf13/jwalterweatherman" ) -type Frame struct { - Turn int - State string -} - -type GameMetadata struct { - BoardSize int - Winner string -} +var frames []board.GameEvent // Used to store state for each SnakeState while running a local game type SnakeState struct { @@ -228,7 +220,9 @@ func (gameState *GameState) Run() error { boardServer := board.NewBoardServer(boardGame) if gameState.outputFile != nil { + // insert initial game start into database bytes, err := json.Marshal(boardGame) + if err != nil { log.WARN.Printf("Failed to serialize frame event for turn%v", err) } else { @@ -367,6 +361,8 @@ func (gameState *GameState) Run() error { boardServer.SendEvent(endEvent) if gameState.outputFile != nil { + // write frames array to db + // insert game end into database bytes, err := json.Marshal(endEvent) if err != nil { // log.WARN.Printf("Unable to serialize game end event: %v", err) @@ -838,6 +834,9 @@ func (gameState *GameState) buildFrameEvent(boardState *rules.BoardState) board. // === New: Write frame event to output file if set === if gameState.outputFile != nil { + // add frame event to array for now, will write to db at end of game + frames = append(frames, gameEvent) + bytes, err := json.Marshal(gameEvent) if err != nil { log.WARN.Printf("Failed to serialize frame event for turn %d: %v", boardState.Turn, err)