DEV 1303: Add empty and royale maps and update game map interface (#72)
* move random generator into Settings * add empty and royale maps * place snakes on either cardinal or corner positions first
This commit is contained in:
parent
6fa2da2f01
commit
e94d758a9b
12 changed files with 479 additions and 52 deletions
74
maps/royale.go
Normal file
74
maps/royale.go
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package maps
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/BattlesnakeOfficial/rules"
|
||||
)
|
||||
|
||||
type RoyaleHazardsMap struct{}
|
||||
|
||||
func init() {
|
||||
globalRegistry.RegisterMap("royale", RoyaleHazardsMap{})
|
||||
}
|
||||
|
||||
func (m RoyaleHazardsMap) ID() string {
|
||||
return "royale"
|
||||
}
|
||||
|
||||
func (m RoyaleHazardsMap) Meta() Metadata {
|
||||
return Metadata{
|
||||
Name: "Royale",
|
||||
Description: "A map where hazards are generated every N turns",
|
||||
Author: "Battlesnake",
|
||||
}
|
||||
}
|
||||
|
||||
func (m RoyaleHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
|
||||
return StandardMap{}.SetupBoard(lastBoardState, settings, editor)
|
||||
}
|
||||
|
||||
func (m RoyaleHazardsMap) UpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
|
||||
// Royale uses the current turn to generate hazards, not the previous turn that's in the board state
|
||||
turn := lastBoardState.Turn + 1
|
||||
|
||||
if settings.RoyaleSettings.ShrinkEveryNTurns < 1 {
|
||||
return errors.New("royale game can't shrink more frequently than every turn")
|
||||
}
|
||||
|
||||
if turn < settings.RoyaleSettings.ShrinkEveryNTurns {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset hazards every turn and re-generate them
|
||||
editor.ClearHazards()
|
||||
|
||||
// Get random generator for turn zero, because we're regenerating all hazards every time.
|
||||
randGenerator := settings.GetRand(0)
|
||||
|
||||
numShrinks := turn / settings.RoyaleSettings.ShrinkEveryNTurns
|
||||
minX, maxX := int32(0), lastBoardState.Width-1
|
||||
minY, maxY := int32(0), lastBoardState.Height-1
|
||||
for i := int32(0); i < numShrinks; i++ {
|
||||
switch randGenerator.Intn(4) {
|
||||
case 0:
|
||||
minX += 1
|
||||
case 1:
|
||||
maxX -= 1
|
||||
case 2:
|
||||
minY += 1
|
||||
case 3:
|
||||
maxY -= 1
|
||||
}
|
||||
}
|
||||
|
||||
for x := int32(0); x < lastBoardState.Width; x++ {
|
||||
for y := int32(0); y < lastBoardState.Height; y++ {
|
||||
if x < minX || x > maxX || y < minY || y > maxY {
|
||||
editor.AddHazard(rules.Point{X: x, Y: y})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue