patch trace capture bug in Game

This commit is contained in:
Sorrel Bri 2020-05-12 16:47:17 -07:00
parent 73ba2bb237
commit 475db4e812

View file

@ -347,6 +347,9 @@ const Point = ({x, y, boardSize = 19}) => {
const lastLiberty = getSingleItemFromSet(liberties); const lastLiberty = getSingleItemFromSet(liberties);
lastLiberty.capturing[this.stone * -1].add(this.group); lastLiberty.capturing[this.stone * -1].add(this.group);
} }
if (liberties.size > 1) {
liberties.forEach(liberty => liberty.capturing[this.stone * -1 ].delete(this.group))
}
// if neighbors have one liberty // if neighbors have one liberty
const neighbors = getNeighbors({point: this, Game: game}).filter(neighbor => neighbor.stone === -1 * this.stone) const neighbors = getNeighbors({point: this, Game: game}).filter(neighbor => neighbor.stone === -1 * this.stone)
@ -395,6 +398,14 @@ const Point = ({x, y, boardSize = 19}) => {
// add captures // add captures
const player = game.turn > 0 ? 'b' : 'w'; const player = game.turn > 0 ? 'b' : 'w';
game.playerState[`${player}Captures`] += 1; game.playerState[`${player}Captures`] += 1;
// add as liberty to neighbors
const neighbors = getNeighbors({ point: this, Game: game }).filter(neighbor => neighbor.stone !== 0 && neighbor.group);
neighbors.forEach(neighbor => {
game.groups[neighbor.group].liberties.add(this);
neighbor.checkCaptures(game)
})
return {...game, boardState: {...game.boardState, [this.key]: this}}; return {...game, boardState: {...game.boardState, [this.key]: this}};
} }
} }
@ -409,3 +420,10 @@ module.exports = {
Game, Game,
Point Point
} }
// Game().initGame()
// .makeMove({ player: 'black', pos: { x: 1, y: 1 } }) // 1 2 3
// .makeMove({ player: 'white', pos: { x: 1, y: 2 } }) // 1 1 -1 1
// .makeMove({ player: 'black', pos: { x: 2, y: 2 } }) // 2 -1 1
// .makeMove({ player: 'white', pos: { x: 2, y: 1 } })
// .makeMove({ player: 'black', pos: { x: 1, y: 3 } })