Skip to content

Commit 0a964c6

Browse files
committed
ちょっとよくわからない状態になったときに、盤面の情報を図示してくれるやつがほしかったので作った
1 parent ccc06eb commit 0a964c6

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

goban.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@ var Goban = (function() {
1111
this.WHITE = 1;
1212
var goban = this;
1313

14+
this.CLIView = function(options) {
15+
this.board = options.board;
16+
17+
this.render = function() {
18+
for ( var i = 0; i < this.board.size; i++ ) {
19+
var line = "|";
20+
for ( var j = 0; j < this.board.size; j++ ) {
21+
var val = this.board.data[i*this.board.size + j];
22+
var char;
23+
switch ( val ) {
24+
case goban.BLACK:
25+
char = "×";
26+
break;
27+
case goban.WHITE:
28+
char = "○";
29+
break;
30+
case undefined:
31+
char = " ";
32+
break;
33+
}
34+
line += char;
35+
}
36+
console.log(line + '|');
37+
};
38+
};
39+
return this;
40+
};
41+
1442
this.Board = function(options)
1543
{
1644
this.size = options.size;
@@ -30,8 +58,8 @@ var Goban = (function() {
3058

3159
this.turn = goban.BLACK;
3260

33-
this.viewClass = options.viewClass;
34-
this.viewOptions = options.viewOptions;
61+
this.viewClass = options.viewClass ? options.viewClass : CLIView;
62+
this.viewOptions = options.viewOptions ? options.viewOptions : {};
3563

3664
this.changeTurn = function() {
3765
if (this.turn == goban.BLACK) {

0 commit comments

Comments
 (0)