Castle Wall Hazard Map (#101)

* castle_wall map

Wall of hazards around the board with dangerous bridges.

- add support for all standard board sizes
- hazard placement for all board sizes

* passage food placement for all board sizes

* 4 snake starting positions for all maps

* only one food can spawn on a bridge

* support 8 snakes for all board sizes

support 12 snakes on XLarge and XXLarge board sizes

* max 2 food sm/med/lg and max 4 food on xlg/xxlg

no food in the first 10 turns

* sort generated hazard positions

* remove 'uninteresting' castle wall map board sizes

* refactor castle wall map to align with #103

* align map castle wall meta Name with ID

* set MinPlayers to 1 for castle wall map

* pass max snake/food and startPosition to priv func

* fix castle wall food placement and refactor tests

* avoid food spawn by snake heads on castle wall map

- fixes forced food spawning infront of snake issue on large & xlarge maps with double walls
This commit is contained in:
Blayne Campbell 2022-08-26 10:11:19 -06:00 committed by GitHub
parent 2668788683
commit ba3b882e1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 747 additions and 0 deletions

View file

@ -0,0 +1,67 @@
package maps
import (
"fmt"
"testing"
"github.com/BattlesnakeOfficial/rules"
"github.com/stretchr/testify/require"
)
func TestCastleWallMaps(t *testing.T) {
tests := []struct {
gameMap GameMap
startPositions [][]rules.Point
}{
{
gameMap: CastleWallMediumHazardsMap{},
startPositions: castleWallMediumStartPositions,
},
{
gameMap: CastleWallLargeHazardsMap{},
startPositions: castleWallLargeStartPositions,
},
{
gameMap: CastleWallExtraLargeHazardsMap{},
startPositions: castleWallExtraLargeStartPositions,
},
}
for _, test := range tests {
t.Run(test.gameMap.ID(), func(t *testing.T) {
m := test.gameMap
settings := rules.Settings{}
sizes := test.gameMap.Meta().BoardSizes
for _, s := range sizes {
initialState := rules.NewBoardState(int(s.Width), int(s.Height))
startPositions := test.startPositions
for i := 0; i < int(test.gameMap.Meta().MaxPlayers); i++ {
initialState.Snakes = append(initialState.Snakes, rules.Snake{ID: fmt.Sprint(i), Body: []rules.Point{}})
}
nextState := rules.NewBoardState(int(s.Width), int(s.Height))
editor := NewBoardStateEditor(nextState)
err := m.SetupBoard(initialState, settings, editor)
require.NoError(t, err)
for _, s := range nextState.Snakes {
require.Len(t, s.Body, rules.SnakeStartSize, "Placed snakes should have the right length")
require.Equal(t, s.Health, rules.SnakeMaxHealth, "Placed snakes should have the right health")
require.NotEmpty(t, s.ID, "Snake ID shouldn't be empty (should get copied when placed)")
// Check that the snake is placed at one of the specified start positions
validStart := false
for _, q := range startPositions {
for i := 0; i < len(q); i++ {
if q[i].X == s.Body[0].X && q[i].Y == s.Body[0].Y {
validStart = true
break
}
}
}
require.True(t, validStart, "Snake must be placed in one of the specified start positions")
}
}
})
}
}