refactor ko
This commit is contained in:
parent
ac1c595b70
commit
cb78de4913
1 changed files with 4 additions and 15 deletions
19
js/main.js
19
js/main.js
|
@ -65,10 +65,8 @@ class Point {
|
||||||
this.pos = [ x, y ]
|
this.pos = [ x, y ]
|
||||||
this.stone = 0; // this is where move placement will go 0, 1, -1 'k'
|
this.stone = 0; // this is where move placement will go 0, 1, -1 'k'
|
||||||
this.legal;
|
this.legal;
|
||||||
this.chk = false; // this is where 'chk', 'l'
|
|
||||||
this.capturing = [];
|
this.capturing = [];
|
||||||
this.groupMembers = [];
|
this.groupMembers = [];
|
||||||
this.captureChecked = false;
|
|
||||||
this.neighbors = {
|
this.neighbors = {
|
||||||
top: {},
|
top: {},
|
||||||
btm: {},
|
btm: {},
|
||||||
|
@ -131,12 +129,6 @@ class Point {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
findStone = (stone) => {
|
|
||||||
return this.checkNeighbors().filter(val => {
|
|
||||||
if ( val.stone === (stone) ) return val;
|
|
||||||
});
|
|
||||||
//returns an array of neighbors for the value of stone
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// could use this Array to iterate through and create
|
// could use this Array to iterate through and create
|
||||||
// let boardCreator = new Array(gameState.boardSize).fill(gameState.boardSize);
|
// let boardCreator = new Array(gameState.boardSize).fill(gameState.boardSize);
|
||||||
|
@ -226,7 +218,6 @@ function hoverPreview(evt) {
|
||||||
function checkLegal(point) {
|
function checkLegal(point) {
|
||||||
clearOverlay();
|
clearOverlay();
|
||||||
// first step in logic: is point occupied, or in ko
|
// first step in logic: is point occupied, or in ko
|
||||||
point.chk = true; //check
|
|
||||||
if (point.stone) return false;
|
if (point.stone) return false;
|
||||||
// if point is not empty check if liberties
|
// if point is not empty check if liberties
|
||||||
if (point.getLiberties().length < 1) {
|
if (point.getLiberties().length < 1) {
|
||||||
|
@ -242,26 +233,25 @@ function checkLegal(point) {
|
||||||
function clearOverlay() { //legal and check
|
function clearOverlay() { //legal and check
|
||||||
for (let point in boardState) {
|
for (let point in boardState) {
|
||||||
point = boardState[point];
|
point = boardState[point];
|
||||||
point.chk = false;
|
|
||||||
point.legal = false;
|
point.legal = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCaptures(point) {
|
function resolveCaptures(point) {
|
||||||
if(!point.capturing.length && !point.captureChecked) {
|
if(!point.capturing.length) {
|
||||||
point.checkCapture();
|
point.checkCapture();
|
||||||
}
|
}
|
||||||
if(point.capturing.length) {
|
if(point.capturing.length) {
|
||||||
point.capturing.forEach(cap => {
|
point.capturing.forEach(cap => {
|
||||||
gameState.playerState[gameState.turn > 0 ? 'bCaptures' : 'wCaptures']++;
|
gameState.playerState[gameState.turn > 0 ? 'bCaptures' : 'wCaptures']++;
|
||||||
cap.groupMembers = [];
|
cap.groupMembers = [];
|
||||||
cap.stone = 0;
|
cap.stone = checkKo(point, cap) ? 'k' : 0;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkKo(cap, point) {
|
function checkKo(point, cap) {
|
||||||
return cap.findStone(gameState.turn).length === 4 && point.getLiberties().length;//determines ponnuki
|
if (point.getLiberties().length === 1 && cap.checkNeighbors(stone => stone.stone === gameState.turn * -1)) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickPlaceStone(evt) {
|
function clickPlaceStone(evt) {
|
||||||
|
@ -296,7 +286,6 @@ function clearPass() {
|
||||||
function clearCaptures() {
|
function clearCaptures() {
|
||||||
for (let point in boardState) {
|
for (let point in boardState) {
|
||||||
point = boardState[point];
|
point = boardState[point];
|
||||||
point.captureChk = false;
|
|
||||||
point.capturing = [];
|
point.capturing = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue