Skip to content

Commit

Permalink
Add new arg "delay" to delay board updates by x milliseconds (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com>
  • Loading branch information
exzizt and bvanvugt authored Jul 4, 2021
1 parent d42f5f4 commit 97fbcb3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions cli/commands/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) {
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 97fbcb3

Please sign in to comment.