finish endgame board calculation logic
This commit is contained in:
parent
201407b8ea
commit
70e0e18815
3 changed files with 46 additions and 45 deletions
29
css/main.css
29
css/main.css
|
@ -70,7 +70,7 @@ h1 {
|
||||||
|
|
||||||
h4 {
|
h4 {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin: 1em .25em 0 .25em;
|
margin: 1em .25em 1em .25em;
|
||||||
font-size: 110%;
|
font-size: 110%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,13 @@ h4 {
|
||||||
margin: .25em;
|
margin: .25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#player-meta * .menu-line {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row nowrap;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
div[data-player-meta] {
|
div[data-player-meta] {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
justify-self: stretch;
|
justify-self: stretch;
|
||||||
|
@ -144,22 +151,6 @@ height: 1;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type=number]::-webkit-inner-spin-button,
|
|
||||||
input[type=number]:focus
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.rank-tick {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.rank-tick li {
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
content {
|
content {
|
||||||
background-color: #61a6c2;
|
background-color: #61a6c2;
|
||||||
display: flex !important;
|
display: flex !important;
|
||||||
|
@ -411,7 +402,7 @@ td .dot .seki {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (min-width: 560px) {
|
@media only screen and (min-width: 591px) {
|
||||||
|
|
||||||
#player-meta {
|
#player-meta {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
@ -428,7 +419,7 @@ td .dot .seki {
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (min-width: 500px) {
|
@media only screen and (min-width: 500px) {
|
||||||
|
|
||||||
html {
|
html {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
20
index.html
20
index.html
|
@ -33,15 +33,23 @@
|
||||||
<div id="player-meta">
|
<div id="player-meta">
|
||||||
<div data-player-meta="black">
|
<div data-player-meta="black">
|
||||||
<h4 class="menu-heading">Black</h4>
|
<h4 class="menu-heading">Black</h4>
|
||||||
<span class="menu-heading">Name:</span><input type="text" name="black-name">
|
<span class="menu-heading">Name:</span><input type="text" name="black-name">
|
||||||
<span class="menu-heading">Rank:</span><span id="black-rank">9k</span><input type="button" id="black-rank-up" value="▲"><input type="button" id="black-rank-down" value="▼">
|
<div class="menu-line">
|
||||||
<input type="checkbox" name="black-rank-certain"><label for="black-rank-certain">Rank Certainty</label>
|
<span class="menu-heading">Rank:</span><span id="black-rank">9k</span><input type="button" id="black-rank-up" value="▲"><input type="button" id="black-rank-down" value="▼">
|
||||||
|
</div>
|
||||||
|
<div class="menu-line">
|
||||||
|
<input type="checkbox" name="black-rank-certain"><label for="black-rank-certain">Rank Certainty</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div data-player-meta="white">
|
<div data-player-meta="white">
|
||||||
<h4 class="menu-heading">White</h4>
|
<h4 class="menu-heading">White</h4>
|
||||||
<span class="menu-heading">Name:</span><input type="text" name="white-name">
|
<span class="menu-heading">Name:</span><input type="text" name="white-name">
|
||||||
<span class="menu-heading">Rank:</span><span id="white-rank">9k</span><input type="button" id="white-rank-up" value="▲"><input type="button" id="white-rank-down" value="▼">
|
<div class="menu-heading">
|
||||||
<input type="checkbox" name="white-rank-certain"><label for="white-rank-certain">Rank Certainty</label>
|
<span class="menu-heading">Rank:</span><span id="white-rank">9k</span><input type="button" id="white-rank-up" value="▲"><input type="button" id="white-rank-down" value="▼">
|
||||||
|
</div>
|
||||||
|
<div class="menu-heading">
|
||||||
|
<input type="checkbox" name="white-rank-certain"><label for="white-rank-certain">Rank Certainty</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="game-record-space">
|
<div id="game-record-space">
|
||||||
|
|
42
js/main.js
42
js/main.js
|
@ -189,7 +189,6 @@ class Point {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cycleTerritory = () => {
|
cycleTerritory = () => {
|
||||||
console.log(this);
|
|
||||||
if (this.stone) {
|
if (this.stone) {
|
||||||
this.groupMembers.forEach(pt => pt.territory = pt.territory * -1);
|
this.groupMembers.forEach(pt => pt.territory = pt.territory * -1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -345,10 +344,7 @@ function clickMenu() {
|
||||||
|
|
||||||
function startMenu() {
|
function startMenu() {
|
||||||
modalEl.style.visibility = 'visible';
|
modalEl.style.visibility = 'visible';
|
||||||
changeUpdateKomi();
|
renderMenu;
|
||||||
changeUpdateHandicap();
|
|
||||||
clickUpdatePlayerMeta();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickCloseMenu(evt) {
|
function clickCloseMenu(evt) {
|
||||||
|
@ -491,7 +487,7 @@ function getDate() {
|
||||||
function init() {
|
function init() {
|
||||||
gameState.gameMeta.date = getDate();
|
gameState.gameMeta.date = getDate();
|
||||||
gameState.komi = 5.5; // get komi from player input
|
gameState.komi = 5.5; // get komi from player input
|
||||||
// startMenu();
|
startMenu();
|
||||||
gameState.winner = null;
|
gameState.winner = null;
|
||||||
gameState.pass = null;
|
gameState.pass = null;
|
||||||
// gameState.handicap = ; // get handicap from player input
|
// gameState.handicap = ; // get handicap from player input
|
||||||
|
@ -587,14 +583,12 @@ function calculateWinner() {
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, 0);
|
}, 0);
|
||||||
console.log(whiteTerritory);
|
|
||||||
let blackTerritory = boardState.reduce((acc, pt) => {
|
let blackTerritory = boardState.reduce((acc, pt) => {
|
||||||
if (pt.territory === 1 && pt.stone !== 1) {
|
if (pt.territory === 1 && pt.stone !== 1) {
|
||||||
return acc + (pt.stone === 0 ? 1 : 2);
|
return acc + (pt.stone === 0 ? 1 : 2);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, 0);
|
}, 0);
|
||||||
console.log(blackTerritory);
|
|
||||||
gameState.playerState.wScore =
|
gameState.playerState.wScore =
|
||||||
gameState.playerState.wCaptures
|
gameState.playerState.wCaptures
|
||||||
+ (gameState.komi < 0 ? gameState.komi * -1 : 0)
|
+ (gameState.komi < 0 ? gameState.komi * -1 : 0)
|
||||||
|
@ -609,28 +603,36 @@ function calculateWinner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function endGameSetTerritory() {
|
function endGameSetTerritory() {
|
||||||
// boardState.forEach(pt => {
|
|
||||||
// pt.territory = pt.stone ? pt.stone : 'd'
|
|
||||||
// });
|
|
||||||
let emptyPoints = boardState.filter(pt => !pt.stone);
|
let emptyPoints = boardState.filter(pt => !pt.stone);
|
||||||
emptyPoints.forEach(pt => pt.joinGroup());
|
emptyPoints.forEach(pt => pt.joinGroup());
|
||||||
emptyPointSetTerritory(emptyPoints);
|
emptyPointSetTerritory(emptyPoints);
|
||||||
// boardState.filter(pt => {
|
groupsMarkDeadLive();
|
||||||
// return pt.groupMembers.length < 6 && pt.stone
|
}
|
||||||
// }).forEach(pt => pt.territory = pt.stone * -1);
|
|
||||||
|
function groupsMarkDeadLive() {
|
||||||
|
boardState.filter(pt => (!pt.territory ))
|
||||||
|
.forEach(pt => {
|
||||||
|
debugger;
|
||||||
|
if (pt.groupMembers.some(grpMem => {
|
||||||
|
return grpMem.checkNeighbors().some(nbr => nbr.territory === pt.stone && nbr.stone === 0)
|
||||||
|
})) {
|
||||||
|
pt.groupMembers.forEach(grpMem => grpMem.territory = pt.stone);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
boardState.filter(pt => (!pt.territory)).forEach(pt => {
|
||||||
|
pt.territory = pt.stone * -1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function emptyPointSetTerritory(emptyPoints) {
|
function emptyPointSetTerritory(emptyPoints) {
|
||||||
emptyPoints.filter(pt => !pt.territory && pt.checkNeighbors().filter(nbr => nbr.stone !== 0))
|
emptyPoints.filter(pt => !pt.territory && pt.checkNeighbors().filter(nbr => nbr.stone !== 0))
|
||||||
.forEach(pt => {
|
.forEach(pt => {
|
||||||
console.log(pt);
|
let b = pt.groupMembers.reduce((acc, grpMem) => {
|
||||||
let b = pt.groupMembers.reduce((acc, rdcPt) => {
|
let bNbr = grpMem.checkNeighbors().filter(nbr => nbr.stone === 1).length;
|
||||||
let bNbr = rdcPt.checkNeighbors().filter(nbr => nbr.stone === 1).length;
|
|
||||||
return acc + bNbr;
|
return acc + bNbr;
|
||||||
}, 0);
|
}, 0);
|
||||||
let w = pt.groupMembers.reduce((acc, rdcPt) => {
|
let w = pt.groupMembers.reduce((acc, grpMem) => {
|
||||||
debugger;
|
let wNbr = grpMem.checkNeighbors().filter(nbr => nbr.stone === -1).length;
|
||||||
let wNbr = rdcPt.checkNeighbors().filter(nbr => nbr.stone === -1).length;
|
|
||||||
return acc + wNbr;
|
return acc + wNbr;
|
||||||
}, 0);
|
}, 0);
|
||||||
pt.groupMembers.forEach(grp => {
|
pt.groupMembers.forEach(grp => {
|
||||||
|
|
Loading…
Reference in a new issue