add ko logic and render
This commit is contained in:
parent
8ed69b3b0a
commit
fb106d858c
1 changed files with 21 additions and 6 deletions
27
js/main.js
27
js/main.js
|
@ -93,7 +93,7 @@ class Point {
|
||||||
}
|
}
|
||||||
emptyNeighbor = () => {
|
emptyNeighbor = () => {
|
||||||
let neighborsArr = this.checkNeighbors();
|
let neighborsArr = this.checkNeighbors();
|
||||||
return !!neighborsArr.find(val => val.stone === 0 && !val.chk ); //checked
|
return neighborsArr.find(val => val.stone === 0 && !val.chk ); //checked
|
||||||
// return true if neighboring point is empty;
|
// return true if neighboring point is empty;
|
||||||
}
|
}
|
||||||
checkCapture = () => {
|
checkCapture = () => {
|
||||||
|
@ -176,8 +176,9 @@ function checkLegal(point) {
|
||||||
|
|
||||||
function clearOverlay() { //legal and check
|
function clearOverlay() { //legal and check
|
||||||
for (let point in boardState) {
|
for (let point in boardState) {
|
||||||
boardState[point].chk = false;
|
point = boardState[point];
|
||||||
boardState[point].legal = false;
|
point.chk = false;
|
||||||
|
point.legal = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,14 +186,18 @@ function resolveCaptures(point) {
|
||||||
if( point.checkCapture().length ) {
|
if( point.checkCapture().length ) {
|
||||||
let caps = point.checkCapture()
|
let caps = point.checkCapture()
|
||||||
for (opp in caps) {
|
for (opp in caps) {
|
||||||
|
opp = caps[opp];
|
||||||
gameState.playerState[opp.stone > 0 ? 'bCaptures' : 'wCaptures']++;
|
gameState.playerState[opp.stone > 0 ? 'bCaptures' : 'wCaptures']++;
|
||||||
caps[opp].stone = 0;
|
opp.stone = checkKo(opp, point) ? 'k' : 0;
|
||||||
console.log(opp.stone);
|
console.log(checkKo(opp,point))
|
||||||
console.log(caps[opp]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkKo(cap, point) {
|
||||||
|
return cap.findStone(gameState.turn).length === 4 && !point.emptyNeighbor();//determines ponnuki
|
||||||
|
}
|
||||||
|
|
||||||
function placeStone(evt) {
|
function placeStone(evt) {
|
||||||
// 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]) ];
|
||||||
|
@ -200,10 +205,20 @@ function placeStone(evt) {
|
||||||
//checks that this placement was marked as legal
|
//checks that this placement was marked as legal
|
||||||
if ( !checkLegal(point) ) return;
|
if ( !checkLegal(point) ) return;
|
||||||
point.stone = gameState.turn;
|
point.stone = gameState.turn;
|
||||||
|
clearKoClearPass();
|
||||||
resolveCaptures(point);
|
resolveCaptures(point);
|
||||||
gameState.turn*= -1;
|
gameState.turn*= -1;
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearKoClearPass() {
|
||||||
|
for (let point in boardState) {
|
||||||
|
point = boardState[point];
|
||||||
|
point.stone = point.stone === 'k' ? 0 : point.stone;
|
||||||
|
gameState.pass = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
gameState.winner = null;
|
gameState.winner = null;
|
||||||
gameState.pass = null;
|
gameState.pass = null;
|
||||||
|
|
Loading…
Reference in a new issue