DEV-1558-healing-pools-map (#94)

* Adding a basic map that adds a few hazards based on fixed coordinates to the map.

* Used wrong board size definitions
This commit is contained in:
Chris Hoefgen 2022-07-28 11:07:27 -07:00 committed by GitHub
parent 7d9a9fb1ab
commit 215a0ea998
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 150 additions and 0 deletions

92
maps/healing_pools.go Normal file
View file

@ -0,0 +1,92 @@
package maps
import (
"github.com/BattlesnakeOfficial/rules"
)
type HealingPoolsMap struct{}
func init() {
globalRegistry.RegisterMap("healing_pools", HealingPoolsMap{})
}
func (m HealingPoolsMap) ID() string {
return "healing_pools"
}
func (m HealingPoolsMap) Meta() Metadata {
return Metadata{
Name: "Healing Pools",
Description: "A simple map that spawns fixed single cell hazard areas based on the map size.",
Author: "Battlesnake",
Version: 1,
MinPlayers: 1,
MaxPlayers: 8,
BoardSizes: FixedSizes(Dimensions{7, 7}, Dimensions{11, 11}, Dimensions{19, 19}),
}
}
func (m HealingPoolsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
if err := (StandardMap{}).SetupBoard(initialBoardState, settings, editor); err != nil {
return err
}
rand := settings.GetRand(0)
options, ok := poolLocationOptions[rules.Point{X: initialBoardState.Width, Y: initialBoardState.Height}]
if !ok {
return rules.RulesetError("board size is not supported by this map")
}
i := rand.Intn(len(options))
for _, p := range options[i] {
editor.AddHazard(p)
}
return nil
}
func (m HealingPoolsMap) UpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
return StandardMap{}.UpdateBoard(lastBoardState, settings, editor)
}
var poolLocationOptions = map[rules.Point][][]rules.Point{
{X: 7, Y: 7}: {
{
{X: 3, Y: 3},
},
},
{X: 11, Y: 11}: {
{
{X: 3, Y: 3},
{X: 7, Y: 7},
},
{
{X: 3, Y: 7},
{X: 7, Y: 3},
},
{
{X: 3, Y: 5},
{X: 7, Y: 5},
},
{
{X: 5, Y: 7},
{X: 5, Y: 3},
},
},
{X: 19, Y: 19}: {
{
{X: 5, Y: 5},
{X: 13, Y: 13},
{X: 5, Y: 13},
{X: 13, Y: 5},
},
{
{X: 5, Y: 10},
{X: 13, Y: 10},
{X: 10, Y: 13},
{X: 10, Y: 5},
},
},
}