made with requirebin
Created
September 10, 2016 13:35
-
-
Save taishi41228/28c3c056fe972f8ff01e40f02c7179d3 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Go { | |
constructor(){ | |
this.co = document.getElementById('cvs').getContext('2d'); | |
this.co.fillStyle = 'red'; | |
this.co.fillRect(50, 50, 100, 100); | |
} | |
draw(ctx){ | |
this.co.globalCompositeOperation = 'destination-over'; | |
this.co.fillStyle = 'green'; | |
this.co.fillRect(0, 0, 600, 250); | |
}; | |
update(ctx){ | |
this.co.globalCompositeOperation = 'source-over'; | |
this.co.fillStyle = 'blue'; | |
this.co.fillRect(75, 75, 100, 100); | |
}; | |
} | |
class Stone { | |
constructor(type, x, y){ | |
this.type = type; | |
this.x = x; | |
this.y = y; | |
} | |
draw(ctx){ | |
}; | |
update(ctx){ | |
}; | |
} | |
String.prototype.toIndexCase = function () { | |
var str = 'abcdefghijklmnopqrs'; | |
var res = ''; | |
res += (str.indexOf(this) + 1).toString(); | |
return res; | |
} | |
/* 各種変数の宣言 */ | |
var selfile = document.getElementById("selfile"); | |
var canvas = document.getElementById('gocanv'); | |
var ctx = canvas.getContext('2d'); | |
var file = null; | |
var reader = new FileReader(); /* ファイルを扱うオブジェクト */ | |
var sgf = ''; /* ファイル内の全テキスト */ | |
var numoflines = 19; /* 盤面の線の数 */ | |
var fillcolor = '#E7C972'; | |
var padding = 10; /* 盤面周囲の余白 */ | |
var go_pad = 20; /* 盤面の余白 */ | |
var go_width = 500 - (padding + go_pad) * 2; | |
var space = go_width / (numoflines - 1); /* 盤面の線の間隔 */ | |
var index = 0; | |
var movings = []; | |
var board = [ | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] | |
]; | |
var checkboard = [ | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] | |
]; | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
checkboard[i][j] = 0; | |
} | |
} | |
function parseCanvas(i) { | |
return padding + go_pad + space * i; | |
} | |
function star(i, j) { | |
ctx.globalCompositeOperation = 'go'; | |
var x = parseCanvas(i - 1); | |
var y = parseCanvas(j - 1); | |
ctx.beginPath(); | |
ctx.fillStyle = '#000000'; | |
ctx.arc(x, y, space / 6, 0, Math.PI * 2.0, false); | |
ctx.fill(); | |
} | |
function goMove(i, j) { | |
ctx.globalCompositeOperation = 'stones'; | |
var x = parseCanvas(j - 1); | |
var y = parseCanvas(i - 1); | |
ctx.beginPath(); | |
if (board[i][j] == 0) { | |
ctx.fillStyle = '#000000'; | |
} else if (board[i][j] == 1) { | |
ctx.fillStyle = '#ffffff'; | |
} else { | |
return; | |
} | |
ctx.arc(x, y, space / 2 - 0.5, 0, Math.PI * 2.0, false); | |
ctx.fill(); | |
ctx.stroke(); | |
} | |
function playtohtml(move) { | |
return '<td>' + move.bw + ' ' + move.x + ' ' + move.y + '</td>'; | |
} | |
function checkDead(bw, x, y) { | |
if (checkboard[y][x] == 1) { | |
return 1; | |
} | |
checkboard[y][x] = 1; | |
if (board[y][x] == -1) { | |
return 0; | |
} | |
console.log(x + ' ' + y); | |
if (board[y][x] == bw) { | |
if (y > 1) { | |
if (checkDead(bw, x, y - 1) == 0) return 0; | |
} | |
if (x > 1) { | |
if (checkDead(bw, x - 1, y) == 0) return 0; | |
} | |
if (y < 19) { | |
if (checkDead(bw, x, y + 1) == 0) return 0; | |
} | |
if (x < 19) { | |
if (checkDead(bw, x + 1, y) == 0) return 0; | |
} | |
} | |
return 1; | |
} | |
function doRemoveStone(bw, x, y) { | |
if (board[y][x] == bw) { | |
board[y][x] = -1; | |
if (y > 1) { | |
doRemoveStone(bw, x, y - 1); | |
} | |
if (x > 1) { | |
doRemoveStone(bw, x - 1, y); | |
} | |
if (y < 19) { | |
doRemoveStone(bw, x, y + 1); | |
} | |
if (x < 19) { | |
doRemoveStone(bw, x + 1, y); | |
} | |
} | |
return 1; | |
} | |
function removeStones(bw, x, y) { | |
if (board[y]) { | |
if (board[y][x] == bw) { | |
return 0; | |
} | |
if (board[y][x] == -1) { | |
return 0; | |
} | |
} else { | |
return 0; | |
} | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
checkboard[i][j] = 0; | |
} | |
} | |
if (checkDead(board[y][x], x, y) == 1) { | |
return doRemoveStone(board[y][x], x, y); | |
} | |
return 0; | |
} | |
function clear() { | |
ctx.globalCompositeOperation = 'stones'; | |
ctx.clearRect(0, 0, 500, 500); | |
} | |
function init() { | |
draw(); | |
} | |
function draw() { | |
ctx.globalCompositeOperation = 'go'; | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
board[i][j] = -1; | |
} | |
} | |
space = go_width / (numoflines - 1); | |
clear(); | |
/* 碁盤の枠 */ | |
ctx.fillStyle = fillcolor; | |
ctx.fillRect(padding, padding, 500 - padding * 2, 500 - padding * 2); | |
ctx.strokeRect(padding, padding, 500 - padding * 2, 500 - padding * 2); | |
/* 碁盤の線 19x19 */ | |
ctx.lineWidth = 1.5; | |
ctx.beginPath(); | |
for (var i = 0; i < numoflines; i++) { | |
ctx.moveTo(padding + go_pad + space * i, padding + go_pad); | |
ctx.lineTo(padding + go_pad + space * i, 500 - (padding + go_pad)); | |
} | |
ctx.stroke(); | |
ctx.beginPath(); | |
for (var i = 0; i < numoflines; i++) { | |
ctx.moveTo(padding + go_pad, padding + go_pad + space * i); | |
ctx.lineTo(500 - (padding + go_pad), padding + go_pad + space * i); | |
} | |
ctx.stroke(); | |
ctx.lineWidth = 1; | |
/* 碁盤の星 */ | |
if (numoflines == 9) { | |
star(5, 5); | |
} else if (numoflines == 13) { | |
star(4, 4); | |
star(10, 4); | |
star(7, 7); | |
star(4, 10); | |
star(10, 10); | |
} else { | |
star(4, 4); | |
star(10, 4); | |
star(16, 4); | |
star(4, 10); | |
star(10, 10); | |
star(16, 10); | |
star(4, 16); | |
star(10, 16); | |
star(16, 16); | |
} | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
checkboard[i][j] = 0; | |
} | |
} | |
for (var i = 0; i < index; i++) { | |
board[movings[i].y][movings[i].x] = movings[i].bw; | |
} | |
for (var i = 1; i < 20; i++) { | |
for (var j = 1; j < 20; j++) { | |
goMove(i, j); | |
} | |
} | |
} | |
init(); | |
var go = new Go(); | |
go.draw(); | |
go.update(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(function(){ | |
;class Go { | |
constructor(){ | |
this.co = document.getElementById('cvs').getContext('2d'); | |
this.co.fillStyle = 'red'; | |
this.co.fillRect(50, 50, 100, 100); | |
} | |
draw(ctx){ | |
this.co.globalCompositeOperation = 'destination-over'; | |
this.co.fillStyle = 'green'; | |
this.co.fillRect(0, 0, 600, 250); | |
}; | |
update(ctx){ | |
this.co.globalCompositeOperation = 'source-over'; | |
this.co.fillStyle = 'blue'; | |
this.co.fillRect(75, 75, 100, 100); | |
}; | |
} | |
class Stone { | |
constructor(type, x, y){ | |
this.type = type; | |
this.x = x; | |
this.y = y; | |
} | |
draw(ctx){ | |
}; | |
update(ctx){ | |
}; | |
} | |
String.prototype.toIndexCase = function () { | |
var str = 'abcdefghijklmnopqrs'; | |
var res = ''; | |
res += (str.indexOf(this) + 1).toString(); | |
return res; | |
} | |
/* 各種変数の宣言 */ | |
var selfile = document.getElementById("selfile"); | |
var canvas = document.getElementById('gocanv'); | |
var ctx = canvas.getContext('2d'); | |
var file = null; | |
var reader = new FileReader(); /* ファイルを扱うオブジェクト */ | |
var sgf = ''; /* ファイル内の全テキスト */ | |
var numoflines = 19; /* 盤面の線の数 */ | |
var fillcolor = '#E7C972'; | |
var padding = 10; /* 盤面周囲の余白 */ | |
var go_pad = 20; /* 盤面の余白 */ | |
var go_width = 500 - (padding + go_pad) * 2; | |
var space = go_width / (numoflines - 1); /* 盤面の線の間隔 */ | |
var index = 0; | |
var movings = []; | |
var board = [ | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] | |
]; | |
var checkboard = [ | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], | |
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] | |
]; | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
checkboard[i][j] = 0; | |
} | |
} | |
function parseCanvas(i) { | |
return padding + go_pad + space * i; | |
} | |
function star(i, j) { | |
ctx.globalCompositeOperation = 'go'; | |
var x = parseCanvas(i - 1); | |
var y = parseCanvas(j - 1); | |
ctx.beginPath(); | |
ctx.fillStyle = '#000000'; | |
ctx.arc(x, y, space / 6, 0, Math.PI * 2.0, false); | |
ctx.fill(); | |
} | |
function goMove(i, j) { | |
ctx.globalCompositeOperation = 'stones'; | |
var x = parseCanvas(j - 1); | |
var y = parseCanvas(i - 1); | |
ctx.beginPath(); | |
if (board[i][j] == 0) { | |
ctx.fillStyle = '#000000'; | |
} else if (board[i][j] == 1) { | |
ctx.fillStyle = '#ffffff'; | |
} else { | |
return; | |
} | |
ctx.arc(x, y, space / 2 - 0.5, 0, Math.PI * 2.0, false); | |
ctx.fill(); | |
ctx.stroke(); | |
} | |
function playtohtml(move) { | |
return '<td>' + move.bw + ' ' + move.x + ' ' + move.y + '</td>'; | |
} | |
function checkDead(bw, x, y) { | |
if (checkboard[y][x] == 1) { | |
return 1; | |
} | |
checkboard[y][x] = 1; | |
if (board[y][x] == -1) { | |
return 0; | |
} | |
console.log(x + ' ' + y); | |
if (board[y][x] == bw) { | |
if (y > 1) { | |
if (checkDead(bw, x, y - 1) == 0) return 0; | |
} | |
if (x > 1) { | |
if (checkDead(bw, x - 1, y) == 0) return 0; | |
} | |
if (y < 19) { | |
if (checkDead(bw, x, y + 1) == 0) return 0; | |
} | |
if (x < 19) { | |
if (checkDead(bw, x + 1, y) == 0) return 0; | |
} | |
} | |
return 1; | |
} | |
function doRemoveStone(bw, x, y) { | |
if (board[y][x] == bw) { | |
board[y][x] = -1; | |
if (y > 1) { | |
doRemoveStone(bw, x, y - 1); | |
} | |
if (x > 1) { | |
doRemoveStone(bw, x - 1, y); | |
} | |
if (y < 19) { | |
doRemoveStone(bw, x, y + 1); | |
} | |
if (x < 19) { | |
doRemoveStone(bw, x + 1, y); | |
} | |
} | |
return 1; | |
} | |
function removeStones(bw, x, y) { | |
if (board[y]) { | |
if (board[y][x] == bw) { | |
return 0; | |
} | |
if (board[y][x] == -1) { | |
return 0; | |
} | |
} else { | |
return 0; | |
} | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
checkboard[i][j] = 0; | |
} | |
} | |
if (checkDead(board[y][x], x, y) == 1) { | |
return doRemoveStone(board[y][x], x, y); | |
} | |
return 0; | |
} | |
function clear() { | |
ctx.globalCompositeOperation = 'stones'; | |
ctx.clearRect(0, 0, 500, 500); | |
} | |
function init() { | |
draw(); | |
} | |
function draw() { | |
ctx.globalCompositeOperation = 'go'; | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
board[i][j] = -1; | |
} | |
} | |
space = go_width / (numoflines - 1); | |
clear(); | |
/* 碁盤の枠 */ | |
ctx.fillStyle = fillcolor; | |
ctx.fillRect(padding, padding, 500 - padding * 2, 500 - padding * 2); | |
ctx.strokeRect(padding, padding, 500 - padding * 2, 500 - padding * 2); | |
/* 碁盤の線 19x19 */ | |
ctx.lineWidth = 1.5; | |
ctx.beginPath(); | |
for (var i = 0; i < numoflines; i++) { | |
ctx.moveTo(padding + go_pad + space * i, padding + go_pad); | |
ctx.lineTo(padding + go_pad + space * i, 500 - (padding + go_pad)); | |
} | |
ctx.stroke(); | |
ctx.beginPath(); | |
for (var i = 0; i < numoflines; i++) { | |
ctx.moveTo(padding + go_pad, padding + go_pad + space * i); | |
ctx.lineTo(500 - (padding + go_pad), padding + go_pad + space * i); | |
} | |
ctx.stroke(); | |
ctx.lineWidth = 1; | |
/* 碁盤の星 */ | |
if (numoflines == 9) { | |
star(5, 5); | |
} else if (numoflines == 13) { | |
star(4, 4); | |
star(10, 4); | |
star(7, 7); | |
star(4, 10); | |
star(10, 10); | |
} else { | |
star(4, 4); | |
star(10, 4); | |
star(16, 4); | |
star(4, 10); | |
star(10, 10); | |
star(16, 10); | |
star(4, 16); | |
star(10, 16); | |
star(16, 16); | |
} | |
for (var i = 0; i < 21; i++) { | |
for (var j = 0; j < 21; j++) { | |
checkboard[i][j] = 0; | |
} | |
} | |
for (var i = 0; i < index; i++) { | |
board[movings[i].y][movings[i].x] = movings[i].bw; | |
} | |
for (var i = 1; i < 20; i++) { | |
for (var j = 1; j < 20; j++) { | |
goMove(i, j); | |
} | |
} | |
} | |
init(); | |
var go = new Go(); | |
go.draw(); | |
go.update(); | |
;}, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <body> --> | |
<canvas id="gocanv" width="500" height="500"></canvas> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <head> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment