###前提・実現したいこと
ここに質問したいことを詳細に書いてください
オセロプログラムの添削をお願いします。
aiも作りたいのですがどのようにやればできますか
置く場所のアシスト機能も付けたいです。
###発生している問題・エラーメッセージ
どこでエラーが起きて表示できないのかわかりません。
###該当のソースコード
//盤面を生成(8×8)する処理 (function(){ var Piece; var showboard=function(){ var b=document.getElementById("board"); while(b.firstChild){ b.removeChild(b.firstChild); } for(var y=1;y<=8;y++){//番兵があるから1から for(var x=1;x<=8;x++){//番兵があるから1から //32ピクセルずつ作っていく var c=Piece[board[x][y]].cloneNode(true); c.style.left=((x-1)*32)+"px"; c.style.top=((y-1)*32)+"px"; b.appendChild(c); if(board[x][y]==0){ (function(){ var t=x; var m=y; c.onclick=function(){ if((Direction conversion)t,m,true){ skip(); //手番交代 Change=3-Change; } }; })(); } } } };
//スペースの確保する処理 var board = []; onload=fanction(){ Change=2; Piece=[document.getElementById("cell")]; for(var i=0;i<10;i++){ board[i]=[]; for(var j=0;j<10;j++){ board[i][j]=0; } } //初期配置 board[4][5]=1;//黒 board[5][4]=1;//黒 board[4][4]=2;//白 board[5][5]=2;//白 showboard(); }; var Change;
var skip=function(){
var kuro=0;
var siro=0;
Change=3-Change;
var message=((turn==1)?"黒":"白");
//選択した箇所の周囲8箇所に石が置けるかどうか判別する
for(var x=1;x<=8;x++){
for(var y=1;y<=8;y++){
if( board[x][y]==0&&Direction conversion(x,y,false)){
document.getElementById("message").innerHTML=message+"の番だよ^^";
showboard();
return;
}
}
}
Change=3-Change;
message+="pass<br>"+((turn==1)?"黒":"白")+"の番だよ^^";
for(x=1;x<=8;x++){
for(y=1;y<=8;y++){
if( board[x][y]==0&&Direction conversion(x,y,false)){
document.getElementById("message").innerHTML=message;
showBoard();
return;
}else{
if(board[x][y]==1){kuro++;}
if(board[x][y]==2){siro++;}
}
}
}
message="黒:"+kuro+"白"+siro+"<br>";
if(kuro==siro){
message+="同点かよ"
alert("終了");
}
else{
message+=((kuro>siro)?"黒":"白")+"の勝ちやで";
alert("終了");
}
document.getElementById("massage").innerHTML=message;
showboard();
};
var Direction conversion=function(x,y,Inside out){
//周囲8箇所が壁,自分の石,空白の場合以降の処理を行わない
for(var fx=-1;fx<=1;fx++){
for(var fy=-1;fy<=1;fy++){
if(dx==0&&dy==0){continue;}
var s=x+dx;
var z=y+dy;
var l=0;
//相手の石を挟んで自分の石がある場合、間の相手の石をひっくり返す
while(board[s][z]==3-Change)[l++;s+=dx;z+=dy;]
if(n>0&&board[s][z]==Change){
return+=l;
if(Inside out){
s=x+dx;
z=y+dy;
while(board[s][z]==3-Change){
board[s][z]=Change;
s+=dx;
z+=dy;
}
bord[x][y]=Change;
}
}
}
}
};
})();
</script> </head> <body> <div style="display:none"> <div id="cell" style="position:absolute;width:33px;height:33px;background-color:#000"> <div style="position:relative;top1px;left:1px;width:31px;height:31px;background-color:#00ee00"> </div> </div> <div id="white" style="position:absolute;width:33px;height:33px;background-color:#000"> <img style="display:block;position:relative;top:1px;left:1px;width:31px;height:31px" src="white.png"> </div> <div id="black" style="position:absolute;width:33px;height:33px;background-color:#000"> <img style="display:block;position:relative;top:1px;left:1px;width:31px;height:31px" src="black.png"> </div> </div> <div id ="board" style="position:absolute;width250px;height:250px;"></div> </body> </html>
回答2件
あなたの回答
tips
プレビュー