DEV-1761: New rules API (#118)
* DEV-1761: Clean up Ruleset interface (#115) * remove legacy ruleset types and simplify ruleset interface * remove unnecessary settings argument from Ruleset interface * decouple rules.Settings from client API and store settings as strings * DEV 1761: Add new BoardState and Point fields (#117) * add Point.TTL, Point.Value, GameState and PointState to BoardState * allow maps to access BoardState.GameState,PointState * add PreUpdateBoard and refactor snail_mode with it * fix bug where an extra turn was printed to the console * fix formatting * fix lint errors Co-authored-by: JonathanArns <jonathan.arns@googlemail.com>
This commit is contained in:
parent
639362ef46
commit
82e1999126
50 changed files with 1349 additions and 1610 deletions
|
|
@ -33,20 +33,25 @@ func (m RoyaleHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings
|
|||
return StandardMap{}.SetupBoard(lastBoardState, settings, editor)
|
||||
}
|
||||
|
||||
func (m RoyaleHazardsMap) UpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
|
||||
func (m RoyaleHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m RoyaleHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
|
||||
// Use StandardMap to populate food
|
||||
if err := (StandardMap{}).UpdateBoard(lastBoardState, settings, editor); err != nil {
|
||||
if err := (StandardMap{}).PostUpdateBoard(lastBoardState, settings, editor); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 {
|
||||
shrinkEveryNTurns := settings.Int(rules.ParamShrinkEveryNTurns, 0)
|
||||
if shrinkEveryNTurns < 1 {
|
||||
return errors.New("royale game can't shrink more frequently than every turn")
|
||||
}
|
||||
|
||||
if turn < settings.RoyaleSettings.ShrinkEveryNTurns {
|
||||
if turn < shrinkEveryNTurns {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +61,7 @@ func (m RoyaleHazardsMap) UpdateBoard(lastBoardState *rules.BoardState, settings
|
|||
// Get random generator for turn zero, because we're regenerating all hazards every time.
|
||||
randGenerator := settings.GetRand(0)
|
||||
|
||||
numShrinks := turn / settings.RoyaleSettings.ShrinkEveryNTurns
|
||||
numShrinks := turn / shrinkEveryNTurns
|
||||
minX, maxX := 0, lastBoardState.Width-1
|
||||
minY, maxY := 0, lastBoardState.Height-1
|
||||
for i := 0; i < numShrinks; i++ {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue