add check for life through friendly groups

This commit is contained in:
Sorrel Bri 2019-08-03 22:40:45 -07:00
parent 07c9ea8fa7
commit da75b4ef77

View file

@ -97,15 +97,19 @@ class Point {
// return true if neighboring point is empty; // return true if neighboring point is empty;
} }
checkCapture = () => { checkCapture = () => {
// console.log(this) let oppStones = this.findStone(gameState.turn * -1)
return this.findStone(gameState.turn * -1).filter(val => !val.emptyNeighbor()); return oppStones.filter(val => !val.emptyNeighbor());
} }
// returns all opposing neighbors that do not have an opposing neighbor // returns all opposing neighbors that do not have an opposing neighbor
checkGroup = () => { // return statement works for first layer bubbling checkGroup = () => { // return statement works for first layer
return this.findStone(gameState.turn).filter(val => val.emptyNeighbor()); let frnStones = this.findStone(gameState.turn)
// if (!this.findStone(gameState.turn).filter(val => val.emptyNeighbor()).length) { if (frnStones.filter(val => val.emptyNeighbor()).length) return frnStones.filter(val => val.emptyNeighbor())
for (let frnStone in frnStones) {
// } frnStone = frnStones[frnStone];
frnStone.chk = true;
if (frnStone.chk === true) return false;
return frnStone.checkGroup();
}
// returns all friendly neighbors that have an empty neighbor // returns all friendly neighbors that have an empty neighbor
} }
@ -149,6 +153,7 @@ init();
let findPointFromIdx = (arr) => boardState.find( point => point.pos[0] === arr[0] && point.pos[1] === arr[1] ); let findPointFromIdx = (arr) => boardState.find( point => point.pos[0] === arr[0] && point.pos[1] === arr[1] );
function hoverPreview(evt) { function hoverPreview(evt) {
evt.stopPropagation();
// renders preview stone if move is legal // renders preview stone if move is legal
let hover = [ parseInt(evt.target.closest('td').id[0]), parseInt(evt.target.closest('td').id[2]) ]; let hover = [ parseInt(evt.target.closest('td').id[0]), parseInt(evt.target.closest('td').id[2]) ];
let point = findPointFromIdx(hover); let point = findPointFromIdx(hover);
@ -195,7 +200,6 @@ function resolveCaptures(point) {
opp = caps[opp]; opp = caps[opp];
gameState.playerState[opp.stone > 0 ? 'bCaptures' : 'wCaptures']++; gameState.playerState[opp.stone > 0 ? 'bCaptures' : 'wCaptures']++;
opp.stone = checkKo(opp, point) ? 'k' : 0; opp.stone = checkKo(opp, point) ? 'k' : 0;
console.log(checkKo(opp,point))
} }
} }
} }
@ -205,6 +209,7 @@ function checkKo(cap, point) {
} }
function placeStone(evt) { function placeStone(evt) {
evt.stopPropagation();
// checks for placement and pushes to cell // checks for placement and pushes to cell
let placement = [ parseInt(evt.target.closest('td').id[0]), parseInt(evt.target.closest('td').id[2]) ]; let placement = [ parseInt(evt.target.closest('td').id[0]), parseInt(evt.target.closest('td').id[2]) ];
let point = findPointFromIdx(placement); let point = findPointFromIdx(placement);