Byte-snake-engine/maps/game_map_test.go
Rob O'Dwyer dab9178a55
DEV 1247: Add a new map generator interface (#71)
* reorganize code

* first draft of map generator interfaces

* add explicit random interface to board helpers

* implement standard map

* rename Generator to GameMap

* allow initializing snakes separately from placing them

* add random number generator to Settings

* updates to GameMap interface

* add helpers for creating and updating BoardState with maps
2022-05-11 08:26:28 -07:00

64 lines
1.6 KiB
Go

package maps
import (
"testing"
"github.com/BattlesnakeOfficial/rules"
"github.com/stretchr/testify/require"
)
func TestBoardStateEditorInterface(t *testing.T) {
var _ Editor = (*BoardStateEditor)(nil)
}
func TestBoardStateEditor(t *testing.T) {
boardState := rules.NewBoardState(11, 11)
boardState.Snakes = append(boardState.Snakes, rules.Snake{
ID: "existing_snake",
Health: 100,
})
editor := BoardStateEditor{BoardState: boardState}
editor.AddFood(rules.Point{X: 1, Y: 3})
editor.AddFood(rules.Point{X: 3, Y: 6})
editor.AddFood(rules.Point{X: 3, Y: 7})
editor.RemoveFood(rules.Point{X: 3, Y: 6})
editor.AddHazard(rules.Point{X: 1, Y: 3})
editor.AddHazard(rules.Point{X: 3, Y: 6})
editor.AddHazard(rules.Point{X: 3, Y: 7})
editor.RemoveHazard(rules.Point{X: 3, Y: 6})
editor.PlaceSnake("existing_snake", []rules.Point{{X: 5, Y: 2}, {X: 5, Y: 1}, {X: 5, Y: 0}}, 99)
editor.PlaceSnake("new_snake", []rules.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}}, 98)
require.Equal(t, &rules.BoardState{
Width: 11,
Height: 11,
Food: []rules.Point{
{X: 1, Y: 3},
{X: 3, Y: 7},
},
Hazards: []rules.Point{
{X: 1, Y: 3},
{X: 3, Y: 7},
},
Snakes: []rules.Snake{
{
ID: "existing_snake",
Health: 99,
Body: []rules.Point{{X: 5, Y: 2}, {X: 5, Y: 1}, {X: 5, Y: 0}},
},
{
ID: "new_snake",
Health: 98,
Body: []rules.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}},
},
},
}, boardState)
editor.ClearFood()
require.Equal(t, []rules.Point{}, boardState.Food)
editor.ClearHazards()
require.Equal(t, []rules.Point{}, boardState.Hazards)
}