* 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>
42 lines
850 B
Go
42 lines
850 B
Go
package rules
|
|
|
|
var wrappedRulesetStages = []string{
|
|
StageGameOverStandard,
|
|
StageMovementWrapBoundaries,
|
|
StageStarvationStandard,
|
|
StageHazardDamageStandard,
|
|
StageFeedSnakesStandard,
|
|
StageEliminationStandard,
|
|
}
|
|
|
|
func MoveSnakesWrapped(b *BoardState, settings Settings, moves []SnakeMove) (bool, error) {
|
|
if IsInitialization(b, settings, moves) {
|
|
return false, nil
|
|
}
|
|
|
|
_, err := MoveSnakesStandard(b, settings, moves)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
for i := 0; i < len(b.Snakes); i++ {
|
|
snake := &b.Snakes[i]
|
|
if snake.EliminatedCause != NotEliminated {
|
|
continue
|
|
}
|
|
snake.Body[0].X = wrap(snake.Body[0].X, 0, b.Width-1)
|
|
snake.Body[0].Y = wrap(snake.Body[0].Y, 0, b.Height-1)
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
|
|
func wrap(value, min, max int) int {
|
|
if value < min {
|
|
return max
|
|
}
|
|
if value > max {
|
|
return min
|
|
}
|
|
return value
|
|
}
|