var koma=new Array();
var pos=new Array();
var ban=new Array();
var hand=new Array();
var mode;
var number_sel;
var koma_sel=new Array();
var number_dir;
var dir=new Array();
var pos_step=new Array();
var hand_step=new Array();
var pos_ch=new Array();
var number_ch;
var pos_de=new Array();
var hand_de=new Array();
var number_de;
function sample(){
for(s=1;s<100;s++){
pos_ch[s]=new Array();
pos_de[s]=new Array();
hand_de[s]=new Array();
}
for(s=0;s<10;s++){
ban[s]=new Array();
}
ban[0][0]=0;
ban[0][1]=0;
sx=0;
for(y1=1;y1<4;y1++){
for(x1=1;x1<4;x1++){
sx=sx+1;
ban[sx][0]=x1;
ban[sx][1]=y1;
}
}
koma[1]="王";
koma[2]="歩";
koma[3]="歩";
koma[4]="王";
koma[5]="歩";
koma[6]="歩";
faststep();
var timer;
var delay = 1000;
var loop = function () {
num_c=num_c+1;
select();
number_ch=0;
for(m=1;m<number_sel+1;m++){
mx=koma_sel[m];
makedir(hand[mx],koma[mx]);
for(c=1;c<number_dir+1;c++){
step(mx,dir[c]);
number_ch=number_ch+1;
for(s=1;s<7;s++){
pos_ch[number_ch][s]=pos_step[s];
}
}
}
number_de=0;
for(s=1;s<number_ch+1;s++){
for(sx=1;sx<7;sx++){
pos_step[sx]=pos_ch[s][sx];
}
ch=check();
if(ch<50){
number_de=number_de+1;
for(sx=1;sx<7;sx++){
pos_de[number_de][sx]=pos_step[sx];
hand_de[number_de][sx]=hand_step[sx];
}
}
}
for(s=1;s<number_de+1;s++){
for(sx=1;sx<7;sx++){
pos_step[sx]=pos_de[s][sx];
hand_step[sx]=hand[sx];
}
change();
for(sx=1;sx<7;sx++){
pos_de[number_de][sx]=pos_step[sx];
hand_de[number_de][sx]=hand_step[sx];
}
}
r1=number_de*Math.random();
r2=Math.floor(r1)+1;
for(sx=1;sx<7;sx++){
pos[sx]=pos_de[r2][sx];
hand[sx]=hand_de[r2][sx];
}
win();
paint();
if(mode=="後手勝利")faststep();
if(mode=="先手勝利")faststep();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function faststep(){
num_c=0;
mode="先手";
hand[1]="先手";
hand[2]="先手";
hand[3]="先手";
hand[4]="後手";
hand[5]="後手";
hand[6]="後手";
pos[1]=2;
pos[2]=1;
pos[3]=3;
pos[4]=8;
pos[5]=7;
pos[6]=9;
}
function paint(){
var a=new Array();
for(s=1;s<4;s++){
a[s]=new Array();
}
for(s=1;s<4;s++){
for(sx=1;sx<4;sx++){
a[s][sx]="〇"
}}
for(s=1;s<7;s++){
p1=pos[s];
x1=ban[p1][0];
y1=ban[p1][1];
if(p1>0)a[y1][x1]=koma[s];
}
str="<table>";
for(s=1;s<4;s++){
str=str+"</tr>";
for(sx=1;sx<4;sx++){
str=str+"<td>"+a[4-s][sx]+"</td>"
}
str=str+"</tr>";
}
str=str+"</table>";
str=str+num_c;
$("#memo").html(str);
}
function win(){
mm=mode;
if(mm=="後手")mode="先手";
if(mm=="先手")mode="後手";
if(hand[1]=="後手")mode="後手勝利";
if(hand[4]=="先手")mode="先手勝利";
}
function change(){
var cou=new Array();
for(s1=0;s1<10;s1++){
cou[s1]=0;
}
for(s1=1;s1<7;s1++){
s2=pos_step[s1];
if(s2<0)s2=0;
if(hand[s1]==mode)cou[s2]=cou[s2]+1;
}
for(s1=1;s1<7;s1++){
s2=pos_step[s1];
if(cou[s1]>1)h=100;
if(hand_step[s1]==mode)h=0;
if(h>50)pos_step[s1]=0;
if(h>50)hand_step[s1]=mode;
}
}
function check(){
var cou=new Array();
for(s1=0;s1<10;s1++){
cou[s1]=0;
}
for(s1=1;s1<7;s1++){
s2=pos_step[s1];
if(s2<0)s2=0;
if(hand[s1]==mode)cou[s2]=cou[s2]+1;
}
ch=0;
for(s1=1;s1<10;s1++){
if(cou[s1]>1)ch=100;
}
for(s1=1;s1<7;s1++){
if(pos_step[s1]<0)ch=100;
}
return ch;
}
function step(mx,d1){
sx=pos[mx];
x1=ban[sx][0]+d1[0];
y1=ban[sx][1]+d1[1];
p1=point(x1,y1);
for(cc=1;cc<7;cc++){
pos_step[cc]=pos[cc];
}
pos_step[mx]=p1;
}
function point(x1,y1){
cc=-1;
for(dd=1;dd<10;dd++){
h=0;
if(ban[dd][0]==x1)h=h+1;
if(ban[dd][1]==y1)h=h+1;
if(h==2)cc=dd;
}
return cc;
}
function makedir(h1,k1){
for(s=1;s<10;s++){
dir[s]=new Array();
}
if (k1=="王"){
dir[1][0]=1;
dir[1][1]=1;
dir[2][0]=-1;
dir[2][1]=1;
dir[3][0]=0;
dir[3][1]=1;
dir[4][0]=1;
dir[4][1]=0;
dir[5][0]=-1;
dir[5][1]=0;
dir[6][0]=-1;
dir[6][1]=-1;
dir[7][0]=0;
dir[7][1]=-1;
dir[8][0]=1;
dir[8][1]=-1;
number_dir=8;
}
h=0;
if(k1=="歩")h=h+1;
if(h1=="先手")h=h+1;
if(h==2){
dir[1][0]=0;
dir[1][1]=1;
number_dir=1;
}
h=0;
if(k1=="歩")h=h+1;
if(h1=="後手")h=h+1;
if(h==2){
dir[1][0]=0;
dir[1][1]=-1;
number_dir=1;
}
}
function select(){
var s,sx;
sx=0;
for(s=1;s<7;s++){
h=0;
if(hand[s]==mode)h=h+1;
if(pos[s]>0)h=h+1;
if(h==2)sx=sx+1;
if(h==2)koma_sel[sx]=s;
}
number_sel=sx;
}
最終更新:2018年01月17日 06:43