Skip to content

Commit

Permalink
isDeadのAPIを少しかえる
Browse files Browse the repository at this point in the history
  • Loading branch information
walf443 committed Jul 31, 2011
1 parent 6a10342 commit 37e88e0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
31 changes: 20 additions & 11 deletions goban.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,56 @@ var Goban = (function() {
};

this.evaluate = function(x, y) {
if (this.isDead(x, y)) {
if (this.isDead(x, y, this.turn)) {
} else {
// no op.
}
};

this.isDead = function(x, y) {
this.isDead = function(x, y, color) {
console.log("############ called isDaed x: " + x + ", y: " + y);
var up = this.point(x, y - 1);
var down = this.point(x, y + 1);
var left = this.point(x - 1, y);
var right = this.point(x + 1, y);

if (
(up == undefined) ||
(down == undefined) ||
(left == undefined) ||
(right == undefined)
(y - 1 >= 0 && up != color ) ||
(y + 1 < this.size && down != color) ||
(x - 1 >= 0 && left != color) ||
(x + 1 < this.size && right != color)
) {
console.log("############ finish called isDaed x: " + x + ", y: " + y);
return false;
}

// up
if (! this.isDead(this.point(x, y - 1))) {
return false;
if ( y - 1 >= 0 ) {
if ( ! this.isDead(x, y - 1, color) ) {
console.log("############ finish called isDaed x: " + x + ", y: " + y);
return false;
}
}

// down
if (! this.isDead(this.point(x, y + 1))) {
if (y + 1 < this.size && ! this.isDead(x, y + 1, color)) {
console.log("############ finish called isDaed x: " + x + ", y: " + y);
return false;
}

// left
if (! this.isDead(this.point(x - 1, y))) {
if (x - 1 >= 0 && ! this.isDead(x - 1, y, color)) {
console.log("############ finish called isDaed x: " + x + ", y: " + y);
return false;
}

// right
if (! this.isDead(this.point(x + 1, y))) {
if (x + 1 < this.size && ! this.isDead(x + 1, y, color)) {
console.log("############ finish called isDaed x: " + x + ", y: " + y);
return false;
}

console.log("############ finish called isDaed x: " + x + ", y: " + y);
return true;
};

Expand Down
4 changes: 2 additions & 2 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<script>
qunitTap(QUnit, function() { console.log.apply(console, arguments); }, {noPlan: true});
</script>
<script type="text/javascript" src="./goban.js"></script>
<script type="text/javascript" src="./test/test_goban.js"></script>
<script type="text/javascript" src="./goban.js?2"></script>
<script type="text/javascript" src="./test/test_goban.js?4"></script>
<script type="text/javascript" src="./test/test_canvas_view.js"></script>
</head>
<body>
Expand Down
8 changes: 3 additions & 5 deletions test/test_goban.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ QUnit.test("隅", function() {
board.point(0, 0, Goban.BLACK);
board.point(1, 0, Goban.WHITE);
board.point(0, 1, Goban.WHITE);
QUnit.equal(board.isDead(0, 0), true, "黒石は取られること");
QUnit.equal(board.isDead(0, 0, Goban.BLACK), true, "黒石は取られること");
});

QUnit.test("辺", function() {
Expand All @@ -48,8 +48,7 @@ QUnit.test("辺", function() {
board.point(0, 2, Goban.WHITE);
board.point(1, 3, Goban.WHITE);
board.point(0, 4, Goban.WHITE);
console.log(board.data);
QUnit.equal(board.isDead(0, 3), true, "黒石は取られること");
QUnit.equal(board.isDead(0, 3, Goban.BLACK), true, "黒石は取られること");
});

QUnit.test("一子", function() {
Expand All @@ -59,8 +58,7 @@ QUnit.test("一子", function() {
board.point(3, 2, Goban.WHITE);
board.point(3, 4, Goban.WHITE);
board.point(4, 3, Goban.WHITE);
console.log(board.data);
QUnit.equal(board.isDead(3, 3), true, "黒石は取られること");
QUnit.equal(board.isDead(3, 3, Goban.BLACK), true, "黒石は取られること");
});
QUnit.start();

0 comments on commit 37e88e0

Please sign in to comment.