From 9796c2e97021f41e1b474290b373293ebfce6d85 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 2 Apr 2023 19:25:53 -0700 Subject: [PATCH] First round of substantial bug fixes --- cardsim/terminalui.go | 13 +++++++------ go.mod | 6 ++++++ go.sum | 8 ++++++++ smoketest/main.go | 18 +++++++++++++++++- 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 go.sum diff --git a/cardsim/terminalui.go b/cardsim/terminalui.go index db1dc84..028b8e7 100644 --- a/cardsim/terminalui.go +++ b/cardsim/terminalui.go @@ -8,13 +8,14 @@ import ( ) func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error { - for { - err := p.StartNextTurn() - if p.DebugLevel < 1 && IsSeriousError(err) { - return err - } - p.ReportError(err) + err := p.StartNextTurn() + if p.DebugLevel < 1 && IsSeriousError(err) { + return err + } + p.ReportError(err) + + for { for p.CanAct() { isCard, cardIdx, choiceIdx, err := pickNextAction(p) p.ReportError(err) diff --git a/go.mod b/go.mod index 6af515c..65ed7e9 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,9 @@ module cardSimEngine go 1.20 + +require ( + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/rogpeppe/go-internal v1.9.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f5733ef --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= diff --git a/smoketest/main.go b/smoketest/main.go index 9229ea1..1773def 100644 --- a/smoketest/main.go +++ b/smoketest/main.go @@ -4,6 +4,8 @@ package main import ( "cardSimEngine/cardsim" "fmt" + + "github.com/kr/pretty" ) func main() { @@ -38,6 +40,7 @@ func main() { Name: cardsim.MsgStr("Stats"), Intro: cardsim.MsgStr("Hi! These are the smoke test stats."), }, + ruledumper{}, } p.Prompt = prompt{} p.DebugLevel = 5 @@ -58,5 +61,18 @@ func (prompt) Title(p *cardsim.Player[*SmokeTestCollection]) cardsim.Message { } func (prompt) Info(p *cardsim.Player[*SmokeTestCollection]) ([]cardsim.Message, error) { - return []cardsim.Message{cardsim.MsgStr("Here, have some stuff.")}, nil + return []cardsim.Message{ + cardsim.MsgStr("Here, have some stuff."), + cardsim.Msgf("It's turn %d according to the player and turn %d according to me.", p.TurnNumber, p.Stats.Turns.Value), + }, nil +} + +type ruledumper struct{} + +func (ruledumper) Title(p *player) cardsim.Message { + return cardsim.MsgStr("Rule Dumper") +} + +func (ruledumper) Info(p *player) ([]cardsim.Message, error) { + return []cardsim.Message{cardsim.Msgf("%# v", pretty.Formatter(p.Rules))}, nil }