var koma,pos,ban,hand,mode;
var koma_sel,dir;
function sample(){
koma=["王","歩","歩","王","歩","歩"];
pos=[2,1,3,8,7,9]
ban=[[0,0],[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]];
hand=["先手","先手","先手","後手","後手","後手"];
mode="先手";
koma_sel=select();
for (u in koma_sel){
dir=make_dir(hand[u],koma[u]);
for(d1 in dir){
p1=pos[u];
x1=ban[p1][1]+d1[1];
y1=ban[p1][0]+d1[0];
p1=point(y1,x1);
alert(p1);
}
}
paint();
}
function point(y1,x1){
z=[y1,x1];
p1=ban.indexOf(z);
return p1;
}
function make_dir(h1,k1){
var dir=new Array();
if (k1=="王"){
dir.push([1,1]);
dir.push([1,-1]);
dir.push([-1,1]);
dir.push([-1,-1]);
dir.push([1,0]);
dir.push([0,1]);
dir.push([-1,0]);
dir.push([0,-1]);
}
h=0
if (k1=="歩")h=h+1;
if (h1=="先手")h=h+1;
if (h==2)dir.push([0,1]);
h=0
if (k1=="歩")h=h+1;
if (h1=="後手")h=h+1;
if (h==2)dir.push([0,-1]);
return dir;
}
function select(){
var koma_sel=new Array();
for(s=0;s<6;s++){
h=0;
if(hand[s]==mode)h=h+1;
if(pos[s]>0)h=h+1;
if(h==2)koma_sel.push(s);
}
return koma_sel;
}
function paint(){
sh=new Array();
for(s=1;s<4;s++){
sh[s]=new Array();
}
for(s=1;s<4;s++){
for(sx=1;sx<4;sx++){
sh[s][sx]="";
}
}
for(s=0;s<6;s++){
sx=pos[s];
x1=ban[sx][1];
y1=ban[sx][0];
if(sx>0)sh[y1][x1]=koma[s];
}
str="<table>";
for(s=1;s<4;s++){
str=str+"<tr>";
for(sx=1;sx<4;sx++){
str=str+"<td>"+sh[4-s][sx]+"</td>";
}
str=str+"</tr>";
}
str=str+"</table>"
$("#memo").html(str);
}
最終更新:2018年01月15日 09:56