fix for rivers and bridges snake start positions (#85)

* fix for rivers and bridges snake start positions

* update max player count, add unit test

* set player count to 12 (max for smallest size)

* fix: one of the 19x19 spawn points

* randomize snake placement at start positions

* randomly choose starts in quadrants

* fix: check that start positions are valid

* modify food placement to avoid hazards
This commit is contained in:
Torben 2022-06-28 14:41:01 -07:00 committed by GitHub
parent f58df66e69
commit 9d6b1147cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 298 additions and 25 deletions

View file

@ -0,0 +1,46 @@
package maps
import (
"fmt"
"testing"
"github.com/BattlesnakeOfficial/rules"
"github.com/stretchr/testify/require"
)
func TestRiversAndBridgesSnakePlacement(t *testing.T) {
m := RiverAndBridgesHazardsMap{}
settings := rules.Settings{}
// check all the supported sizes
for _, size := range []int{11, 19, 25} {
initialState := rules.NewBoardState(size, size)
startPositions := riversAndBridgesStartPositions[rules.Point{X: size, Y: size}]
maxSnakes := len(startPositions)
for i := 0; i < maxSnakes; i++ {
initialState.Snakes = append(initialState.Snakes, rules.Snake{ID: fmt.Sprint(i), Body: []rules.Point{}})
}
nextState := rules.NewBoardState(size, size)
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")
}
}
}