@@ -50,6 +50,10 @@ func convertBoardToMatrix(state internal.GameState) matrix {
50
50
obj = you
51
51
}
52
52
for _ , coord := range snake .Body {
53
+ if coord .Equals (snake .Head ) && obj != you {
54
+ grid = addCoordToMatrix (coord , grid , snake .ID )
55
+ continue
56
+ }
53
57
grid = addCoordToMatrix (coord , grid , obj .String ())
54
58
}
55
59
}
@@ -75,25 +79,54 @@ func addCoordToMatrix(coord internal.Coord, grid matrix, object string) matrix {
75
79
return grid
76
80
}
77
81
78
- func potentialPositions (head internal.Coord ) choices {
79
- return choices {
82
+ func potentialPositions (head internal.Coord , state internal. GameState ) choices {
83
+ c := choices {
80
84
left : internal.Coord {X : head .X - 1 , Y : head .Y },
81
85
right : internal.Coord {X : head .X + 1 , Y : head .Y },
82
86
up : internal.Coord {X : head .X , Y : head .Y + 1 },
83
87
down : internal.Coord {X : head .X , Y : head .Y - 1 },
84
88
}
89
+
90
+ if state .Game .Ruleset .Name == "wrapped" {
91
+ return wrappedPotentialPositions (c , state .Board )
92
+ }
93
+
94
+ return c
85
95
}
86
96
87
- func checkPossible ( initialState internal. GameState , grid matrix , potential internal.Coord , otherSnakeLength map [ string ] int32 ) bool {
88
- // check walls
89
- if initialState . Game . Ruleset . Name != "wrapped" {
90
- if potential .X >= initialState . Board . Width || potential . X < 0 {
91
- return false
97
+ func wrappedPotentialPositions ( c choices , board internal.Board ) choices {
98
+ for _ , coord := range c {
99
+ if coord . X >= board . Width {
100
+ coord .X = 0
101
+ continue
92
102
}
93
103
94
- if potential .Y >= initialState .Board .Height || potential .Y < 0 {
95
- return false
104
+ if coord .X < 0 {
105
+ coord .X = board .Width - 1
106
+ continue
96
107
}
108
+
109
+ if coord .Y >= board .Height {
110
+ coord .Y = 0
111
+ continue
112
+ }
113
+
114
+ if coord .Y < 0 {
115
+ coord .Y = board .Height - 1
116
+ continue
117
+ }
118
+ }
119
+ return c
120
+ }
121
+
122
+ func checkPossible (initialState internal.GameState , grid matrix , potential internal.Coord , otherSnakeLength map [string ]int32 ) bool {
123
+ // check walls
124
+ if potential .X >= initialState .Board .Width || potential .X < 0 {
125
+ return false
126
+ }
127
+
128
+ if potential .Y >= initialState .Board .Height || potential .Y < 0 {
129
+ return false
97
130
}
98
131
99
132
// check hazards
@@ -148,14 +181,14 @@ func findOptimal(state internal.GameState, movesLeft int) string {
148
181
if snake .ID == state .You .ID {
149
182
continue
150
183
}
151
- p := potentialPositions (snake .Head )
184
+ p := potentialPositions (snake .Head , state )
152
185
for _ , pp := range p {
153
186
grid = moveEnemiesForward (snake .Head , pp , snake , grid )
154
187
}
155
188
}
156
189
157
190
health := float64 (state .You .Health ) / 100
158
- potential := potentialPositions (state .You .Head )
191
+ potential := potentialPositions (state .You .Head , state )
159
192
analysis := map [direction ]float64 {}
160
193
otherSnakes := mapSnakeLengths (state .Board .Snakes )
161
194
for d , p := range potential {
@@ -216,7 +249,7 @@ func lookahead(movesLeft int, r route, initialState internal.GameState, otherSna
216
249
}
217
250
}
218
251
219
- potential := potentialPositions (option )
252
+ potential := potentialPositions (option , initialState )
220
253
grid = addCoordToMatrix (option , grid , you .String ())
221
254
for _ , p := range potential {
222
255
movesLeft --
0 commit comments