Skip to content

Commit

Permalink
wip incremental updates
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Aug 3, 2024
1 parent f69f4a5 commit ed19367
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/main/client/src/model/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,32 +169,28 @@ export function isForbidden(board, groupInfo, currentColor) {
return true
}

export function updateBoard(boardBeforeMove, move) {
export function updateBoard(board, move) {
let {pass, x, y, color} = move
if (pass) {
return boardBeforeMove
return board
}
let board = applyMove(boardBeforeMove, move)
board = applyMove(board, move)
let oppositeColor = color ^ (WHITE | BLACK)
let size = board.length
let result = board
if (y > 0 && board[y - 1][x] === oppositeColor) {
result = removeDeadGroup(board, x, y - 1)
}
if (y < size - 1 && board[y + 1][x] === oppositeColor) {
result = removeDeadGroup(board, x, y + 1)
}
if (x > 0 && board[y][x - 1] === oppositeColor) {
result = removeDeadGroup(board, x - 1, y)
}
if (x < size - 1 && board[y][x + 1] === oppositeColor) {
result = removeDeadGroup(board, x + 1, y)
}
return result
board = removeDeadGroup(board, x, y - 1, oppositeColor)
board = removeDeadGroup(board, x, y + 1, oppositeColor)
board = removeDeadGroup(board, x - 1, y, oppositeColor)
board = removeDeadGroup(board, x + 1, y, oppositeColor)
return board
}

function removeDeadGroup(board, xx, yy) {
function removeDeadGroup(board, xx, yy, color) {
let dim = board.length
if (Math.min(xx, yy) < 0 || Math.max(xx, yy) >= dim) {
return board
}
if (board[yy][xx] !== color) {
return board
}
if (yy > 0 && board[yy - 1][xx] == 0) {
return board
}
Expand All @@ -207,7 +203,6 @@ function removeDeadGroup(board, xx, yy) {
if (xx < dim - 1 && board[yy][xx + 1] == 0) {
return board
}
let color = board[yy][xx]
let acc = new PointList(dim)
let pointsChecked = new PointSet(dim)
pointsChecked.add(xx, yy)
Expand Down

0 comments on commit ed19367

Please sign in to comment.