Add a "Version" field to GameMap Meta (#83)

* initial concept for versioning
* simple uint version implementation
* tidy up dependencies
This commit is contained in:
Torben 2022-06-15 15:51:42 -07:00 committed by GitHub
parent 0f15f34bdf
commit e8e20c53ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 5 deletions

1
go.sum
View file

@ -249,7 +249,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View file

@ -19,6 +19,7 @@ func (m ArcadeMazeMap) Meta() Metadata {
Name: "Arcade Maze", Name: "Arcade Maze",
Description: "Generic arcade maze map with hazard walls", Description: "Generic arcade maze map with hazard walls",
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }

View file

@ -19,6 +19,7 @@ func (m EmptyMap) Meta() Metadata {
Name: "Empty", Name: "Empty",
Description: "Default snake placement with no food", Description: "Default snake placement with no food",
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }

View file

@ -1,6 +1,8 @@
package maps package maps
import "github.com/BattlesnakeOfficial/rules" import (
"github.com/BattlesnakeOfficial/rules"
)
type GameMap interface { type GameMap interface {
// Return a unique identifier for this map. // Return a unique identifier for this map.
@ -20,6 +22,9 @@ type Metadata struct {
Name string Name string
Author string Author string
Description string Description string
// Version is the current version of the game map.
// Each time a map is changed, the version number should be incremented by 1.
Version uint
} }
// Editor is used by GameMap implementations to modify the board state. // Editor is used by GameMap implementations to modify the board state.

View file

@ -29,6 +29,7 @@ func (m InnerBorderHazardsMap) Meta() Metadata {
Name: "hz_inner_wall", Name: "hz_inner_wall",
Description: "Creates a static map on turn 0 that is a 1-square wall of hazard that is inset 2 squares from the edge of the board", Description: "Creates a static map on turn 0 that is a 1-square wall of hazard that is inset 2 squares from the edge of the board",
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }
@ -65,6 +66,7 @@ func (m ConcentricRingsHazardsMap) Meta() Metadata {
Name: "hz_rings", Name: "hz_rings",
Description: "Creates a static map where there are rings of hazard sauce starting from the center with a 1 square space between the rings that has no sauce", Description: "Creates a static map where there are rings of hazard sauce starting from the center with a 1 square space between the rings that has no sauce",
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }
@ -102,6 +104,7 @@ func (m ColumnsHazardsMap) Meta() Metadata {
Name: "hz_columns", Name: "hz_columns",
Description: "Creates a static map on turn 0 that fills in odd squares, i.e. (1,1), (1,3), (3,3) ... with hazard sauce", Description: "Creates a static map on turn 0 that fills in odd squares, i.e. (1,1), (1,3), (3,3) ... with hazard sauce",
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }
@ -137,6 +140,7 @@ func (m SpiralHazardsMap) Meta() Metadata {
Description: `Generates a dynamic hazard map that grows in a spiral pattern clockwise from a random point on Description: `Generates a dynamic hazard map that grows in a spiral pattern clockwise from a random point on
the map. Each 2 turns a new hazard square is added to the map`, the map. Each 2 turns a new hazard square is added to the map`,
Author: "altersaddle", Author: "altersaddle",
Version: 1,
} }
} }
@ -225,6 +229,7 @@ func (m ScatterFillMap) Meta() Metadata {
return Metadata{ return Metadata{
Name: "hz_scatter", Name: "hz_scatter",
Description: `Fills the entire board with hazard squares that are set to appear on regular turn schedule. Each square is picked at random.`, Description: `Fills the entire board with hazard squares that are set to appear on regular turn schedule. Each square is picked at random.`,
Version: 1,
} }
} }
@ -272,6 +277,7 @@ func (m DirectionalExpandingBoxMap) Meta() Metadata {
return Metadata{ return Metadata{
Name: "hz_grow_box", Name: "hz_grow_box",
Description: `Creates an area of hazard that expands from a point with one random side growing on a turn schedule.`, Description: `Creates an area of hazard that expands from a point with one random side growing on a turn schedule.`,
Version: 1,
} }
} }
@ -382,6 +388,7 @@ func (m ExpandingBoxMap) Meta() Metadata {
return Metadata{ return Metadata{
Name: "hz_expand_box", Name: "hz_expand_box",
Description: `Generates an area of hazard that expands from a random point on the board outward in concentric rings on a periodic turn schedule.`, Description: `Generates an area of hazard that expands from a random point on the board outward in concentric rings on a periodic turn schedule.`,
Version: 1,
} }
} }
@ -453,6 +460,7 @@ func (m ExpandingScatterMap) Meta() Metadata {
return Metadata{ return Metadata{
Name: "hz_expand_scatter", Name: "hz_expand_scatter",
Description: `Builds an expanding hazard area that grows from a central point in rings that are randomly filled in on a regular turn schedule.`, Description: `Builds an expanding hazard area that grows from a central point in rings that are randomly filled in on a regular turn schedule.`,
Version: 1,
} }
} }
@ -531,6 +539,7 @@ func (m RiverAndBridgesHazardsMap) Meta() Metadata {
Description: `Creates fixed maps that have a lake of hazard in the middle with rivers going in the cardinal directions. Description: `Creates fixed maps that have a lake of hazard in the middle with rivers going in the cardinal directions.
Each river has one or two 1-square "bridges" over them`, Each river has one or two 1-square "bridges" over them`,
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }

View file

@ -1,6 +1,7 @@
package maps package maps
import ( import (
"fmt"
"testing" "testing"
"github.com/BattlesnakeOfficial/rules" "github.com/BattlesnakeOfficial/rules"
@ -22,7 +23,7 @@ func TestRegisteredMaps(t *testing.T) {
for mapName, gameMap := range globalRegistry { for mapName, gameMap := range globalRegistry {
t.Run(mapName, func(t *testing.T) { t.Run(mapName, func(t *testing.T) {
require.Equalf(t, mapName, gameMap.ID(), "%#v game map doesn't return its own ID", mapName) require.Equalf(t, mapName, gameMap.ID(), "%#v game map doesn't return its own ID", mapName)
require.True(t, gameMap.Meta().Version > 0, fmt.Sprintf("registered maps must have a valid version (>= 1) - '%d' is invalid", gameMap.Meta().Version))
var setupBoardState *rules.BoardState var setupBoardState *rules.BoardState
for width := 0; width < maxBoardWidth; width++ { for width := 0; width < maxBoardWidth; width++ {

View file

@ -21,6 +21,7 @@ func (m RoyaleHazardsMap) Meta() Metadata {
Name: "Royale", Name: "Royale",
Description: "A map where hazards are generated every N turns", Description: "A map where hazards are generated every N turns",
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }

View file

@ -19,6 +19,7 @@ func (m StandardMap) Meta() Metadata {
Name: "Standard", Name: "Standard",
Description: "Standard snake placement and food spawning", Description: "Standard snake placement and food spawning",
Author: "Battlesnake", Author: "Battlesnake",
Version: 1,
} }
} }