forked from BattlesnakeOfficial/rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapped.go
42 lines (36 loc) · 850 Bytes
/
wrapped.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
}