Skip to content

Commit ba48d6d

Browse files
committed
some refactoring
1 parent 36a5e37 commit ba48d6d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/main/client/src/model/count.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import {
22
PointQueue,
33
} from "./PointQueue.js"
4-
import {
5-
PointList,
6-
} from "./PointList.js"
74
import {
85
PointSet,
96
} from "./PointSet.js"
@@ -57,28 +54,24 @@ export function toggleStonesAt(board, xx, yy) {
5754
return board
5855
}
5956
let dim = board.length
60-
let result = new PointList(dim)
6157
let pointsToCheck = new PointQueue(dim)
6258
let pointsChecked = new PointSet(dim)
6359
pointsChecked.add(xx, yy)
6460
pointsToCheck.offer(xx, yy)
61+
let updated = board.slice()
6562
while (!pointsToCheck.isEmpty()) {
6663
let ptId = pointsToCheck.poll()
6764
let y = Math.trunc(ptId / dim)
6865
let x = ptId % dim
69-
result.add(x, y)
66+
if (updated[y] === board[y]) {
67+
updated[y] = board[y].slice()
68+
}
69+
updated[y][x] = toggleRemoved(board[y][x])
7070
updateToggleStonesAt(board, x, y - 1, color, pointsChecked, pointsToCheck)
7171
updateToggleStonesAt(board, x, y + 1, color, pointsChecked, pointsToCheck)
7272
updateToggleStonesAt(board, x - 1, y, color, pointsChecked, pointsToCheck)
7373
updateToggleStonesAt(board, x + 1, y, color, pointsChecked, pointsToCheck)
7474
}
75-
let updated = board.slice()
76-
result.forEach((x, y) => {
77-
if (updated[y] === board[y]) {
78-
updated[y] = board[y].slice()
79-
}
80-
updated[y][x] = toggleRemoved(updated[y][x])
81-
})
8275
return updated
8376
}
8477

0 commit comments

Comments
 (0)