change map support for large #'s of snakes (#92)

* change map support for large #'s of snakes

* test square board fn

* format comment

* add whitespace

* better support large #'s of snakes on small boards

* include an intermediate xlarge size
This commit is contained in:
Torben 2022-07-07 11:14:30 -07:00 committed by GitHub
parent 08cb7ae61d
commit 663c377cc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 174 additions and 101 deletions

View file

@ -19,16 +19,20 @@ func (m EmptyMap) Meta() Metadata {
Name: "Empty",
Description: "Default snake placement with no food",
Author: "Battlesnake",
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
func (m EmptyMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
rand := settings.GetRand(0)
if len(initialBoardState.Snakes) > int(m.Meta().MaxPlayers) {
return rules.ErrorTooManySnakes
}
snakeIDs := make([]string, 0, len(initialBoardState.Snakes))
for _, snake := range initialBoardState.Snakes {
snakeIDs = append(snakeIDs, snake.ID)

View file

@ -42,7 +42,7 @@ func TestEmptyMapSetupBoard(t *testing.T) {
&rules.BoardState{
Width: 7,
Height: 7,
Snakes: generateSnakes(9),
Snakes: generateSnakes(17),
Food: []rules.Point{},
Hazards: []rules.Point{},
},
@ -61,7 +61,7 @@ func TestEmptyMapSetupBoard(t *testing.T) {
},
rules.MinRand,
nil,
rules.ErrorNoRoomForSnake,
rules.ErrorTooManySnakes,
},
{
"full 11x11 min",

View file

@ -42,6 +42,19 @@ func AnySize() sizes {
return sizes{Dimensions{Width: 0, Height: 0}}
}
// OddSizes generates square (width = height) board sizes with an odd number of positions
// in the vertical and horizontal directions.
// Examples:
// - OddSizes(11,21) produces [(11,11), (13,13), (15,15), (17,17), (19,19), (21,21)]
func OddSizes(min, max uint) sizes {
var s sizes
for i := min; i <= max; i += 2 {
s = append(s, Dimensions{Width: i, Height: i})
}
return s
}
// FixedSizes creates dimensions for a board that has 1 or more fixed sizes.
// Examples:
// - FixedSizes(Dimension{9,11}) supports only a width of 9 and a height of 11.

View file

@ -29,10 +29,10 @@ func (m InnerBorderHazardsMap) Meta() Metadata {
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",
Author: "Battlesnake",
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
@ -69,10 +69,10 @@ func (m ConcentricRingsHazardsMap) Meta() Metadata {
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",
Author: "Battlesnake",
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
@ -110,10 +110,10 @@ func (m ColumnsHazardsMap) Meta() Metadata {
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",
Author: "Battlesnake",
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
@ -149,10 +149,10 @@ func (m SpiralHazardsMap) Meta() Metadata {
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`,
Author: "altersaddle",
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
@ -241,10 +241,10 @@ func (m ScatterFillMap) Meta() Metadata {
return Metadata{
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.`,
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
@ -292,10 +292,10 @@ func (m DirectionalExpandingBoxMap) Meta() Metadata {
return Metadata{
Name: "hz_grow_box",
Description: `Creates an area of hazard that expands from a point with one random side growing on a turn schedule.`,
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
@ -406,10 +406,10 @@ func (m ExpandingBoxMap) Meta() Metadata {
return Metadata{
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.`,
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
@ -481,10 +481,10 @@ func (m ExpandingScatterMap) Meta() Metadata {
return Metadata{
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.`,
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}

View file

@ -21,10 +21,10 @@ func (m RoyaleHazardsMap) Meta() Metadata {
Name: "Royale",
Description: "A map where hazards are generated every N turns",
Author: "Battlesnake",
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}

View file

@ -19,16 +19,20 @@ func (m StandardMap) Meta() Metadata {
Name: "Standard",
Description: "Standard snake placement and food spawning",
Author: "Battlesnake",
Version: 1,
Version: 2,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: AnySize(),
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
}
}
func (m StandardMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
rand := settings.GetRand(0)
if len(initialBoardState.Snakes) > int(m.Meta().MaxPlayers) {
return rules.ErrorTooManySnakes
}
snakeIDs := make([]string, 0, len(initialBoardState.Snakes))
for _, snake := range initialBoardState.Snakes {
snakeIDs = append(snakeIDs, snake.ID)

View file

@ -43,7 +43,7 @@ func TestStandardMapSetupBoard(t *testing.T) {
&rules.BoardState{
Width: 7,
Height: 7,
Snakes: generateSnakes(9),
Snakes: generateSnakes(17),
Food: []rules.Point{},
Hazards: []rules.Point{},
},
@ -62,7 +62,7 @@ func TestStandardMapSetupBoard(t *testing.T) {
},
rules.MinRand,
nil,
rules.ErrorNoRoomForSnake,
rules.ErrorTooManySnakes,
},
{
"full 11x11 min",