From 97fbcb33766bc0f6f26fda8a2bb39cfa10bf1e6a Mon Sep 17 00:00:00 2001 From: Luke Mitchell Date: Sun, 4 Jul 2021 13:48:56 -0700 Subject: [PATCH] Add new arg "delay" to delay board updates by x milliseconds (#48) Co-authored-by: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com> --- cli/README.md | 1 + cli/commands/play.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/cli/README.md b/cli/README.md index d47b450..cc8d8fb 100644 --- a/cli/README.md +++ b/cli/README.md @@ -32,6 +32,7 @@ Usage: battlesnake play [flags] Flags: + -d, --delay int32 Turn Delay in Milliseconds (default 0) -g, --gametype string Type of Game Rules (default "standard") -H, --height int32 Height of Board (default 11) -h, --help help for play diff --git a/cli/commands/play.go b/cli/commands/play.go index c4c997f..0ce9866 100644 --- a/cli/commands/play.go +++ b/cli/commands/play.go @@ -100,6 +100,7 @@ var Sequential bool var GameType string var ViewMap bool var Seed int64 +var TurnDelay int32 var playCmd = &cobra.Command{ Use: "play", @@ -121,6 +122,7 @@ func init() { playCmd.Flags().StringVarP(&GameType, "gametype", "g", "standard", "Type of Game Rules") playCmd.Flags().BoolVarP(&ViewMap, "viewmap", "v", false, "View the Map Each Turn") playCmd.Flags().Int64VarP(&Seed, "seed", "r", time.Now().UTC().UnixNano(), "Random Seed") + playCmd.Flags().Int32VarP(&TurnDelay, "delay", "d", 0, "Turn Delay in Milliseconds") } var run = func(cmd *cobra.Command, args []string) { @@ -156,6 +158,10 @@ var run = func(cmd *cobra.Command, args []string) { } else { log.Printf("[%v]: State: %v OutOfBounds: %v\n", Turn, state, outOfBounds) } + + if TurnDelay > 0 { + time.Sleep(time.Duration(TurnDelay) * time.Millisecond) + } } if GameType == "solo" {