@@ -169,32 +169,28 @@ export function isForbidden(board, groupInfo, currentColor) {
169
169
return true
170
170
}
171
171
172
- export function updateBoard ( boardBeforeMove , move ) {
172
+ export function updateBoard ( board , move ) {
173
173
let { pass, x, y, color} = move
174
174
if ( pass ) {
175
- return boardBeforeMove
175
+ return board
176
176
}
177
- let board = applyMove ( boardBeforeMove , move )
177
+ board = applyMove ( board , move )
178
178
let oppositeColor = color ^ ( WHITE | BLACK )
179
- let size = board . length
180
- let result = board
181
- if ( y > 0 && board [ y - 1 ] [ x ] === oppositeColor ) {
182
- result = removeDeadGroup ( board , x , y - 1 )
183
- }
184
- if ( y < size - 1 && board [ y + 1 ] [ x ] === oppositeColor ) {
185
- result = removeDeadGroup ( board , x , y + 1 )
186
- }
187
- if ( x > 0 && board [ y ] [ x - 1 ] === oppositeColor ) {
188
- result = removeDeadGroup ( board , x - 1 , y )
189
- }
190
- if ( x < size - 1 && board [ y ] [ x + 1 ] === oppositeColor ) {
191
- result = removeDeadGroup ( board , x + 1 , y )
192
- }
193
- return result
179
+ board = removeDeadGroup ( board , x , y - 1 , oppositeColor )
180
+ board = removeDeadGroup ( board , x , y + 1 , oppositeColor )
181
+ board = removeDeadGroup ( board , x - 1 , y , oppositeColor )
182
+ board = removeDeadGroup ( board , x + 1 , y , oppositeColor )
183
+ return board
194
184
}
195
185
196
- function removeDeadGroup ( board , xx , yy ) {
186
+ function removeDeadGroup ( board , xx , yy , color ) {
197
187
let dim = board . length
188
+ if ( Math . min ( xx , yy ) < 0 || Math . max ( xx , yy ) >= dim ) {
189
+ return board
190
+ }
191
+ if ( board [ yy ] [ xx ] !== color ) {
192
+ return board
193
+ }
198
194
if ( yy > 0 && board [ yy - 1 ] [ xx ] == 0 ) {
199
195
return board
200
196
}
@@ -207,7 +203,6 @@ function removeDeadGroup(board, xx, yy) {
207
203
if ( xx < dim - 1 && board [ yy ] [ xx + 1 ] == 0 ) {
208
204
return board
209
205
}
210
- let color = board [ yy ] [ xx ]
211
206
let acc = new PointList ( dim )
212
207
let pointsChecked = new PointSet ( dim )
213
208
pointsChecked . add ( xx , yy )
0 commit comments