var x_a=new Array();
var y_a=new Array();
var x_b=new Array();
var y_b=new Array();
var life_a=new Array();
var life_b=new Array();
var mode;
function sample(){
var timer;
var delay = 100;
mode=2;
faststep();
var loop = function(){
m1=mode;
if(m1==1)mode=2;
if(m1==2)mode=1;
if(mode==1)move_a();
if(mode==2)move_b();
game();
paint();
clearTimeout(timer);
timer = setTimeout(loop,delay);
}
loop();
}
function faststep(){
for(s=1;s<10;s++){
x_a[s]=s;
y_a[s]=1;
x_b[s]=s;
y_b[s]=9;
life_a[s]=100;
life_b[s]=100;
}
}
function game(){
for(s=1;s<10;s++){
h=0;
if(y_a[s]>8)h=h+1;
if(life_a[s]>50)h=h+1;
if(h==2)faststep();
}
for(s=1;s<10;s++){
h=0;
if(y_b[s]<2)h=h+1;
if(life_b[s]>50)h=h+1;
if(h==2)faststep();
}
}
function move_a(){
var g=new Array();
sx=0;
for(s=1;s<10;s++){
if(life_a[s]>50)sx=sx+1;
if(life_a[s]>50)g[sx]=s;
}
nn=sx;
n1=nn*Math.random();
n2=Math.floor(n1)+1;
n3=g[n2];
y_a[n3]=y_a[n3]+1;
for(s=1;s<10;s++){
h=0;
if(y_a[n3]==y_b[s])h=h+1;
if(x_a[n3]==x_b[s])h=h+1;
if(life_a[n3]>50)h=h+1;
if(h==3)life_b[s]=0;
}
}
function move_b(){
var g=new Array();
sx=0;
for(s=1;s<10;s++){
if(life_b[s]>50)sx=sx+1;
if(life_b[s]>50)g[sx]=s;
}
nn=sx;
n1=nn*Math.random();
n2=Math.floor(n1)+1;
n3=g[n2];
y_b[n3]=y_b[n3]-1;
for(s=1;s<10;s++){
h=0;
if(y_b[n3]==y_a[s])h=h+1;
if(x_b[n3]==x_a[s])h=h+1;
if(life_b[n3]>50)h=h+1;
if(h==3)life_a[s]=0;
}
}
function paint(){
var sub=new svgpaint();
str="<svg width=\"500\" height=\"500\">";
for(s=1;s<10;s++){
if(life_a[s]>50)str=str+sub.rect(50*x_a[s]
,50*y_a[s],50,50,"red");
if(life_b[s]>50)str=str+sub.rect(50*x_b[s]
,50*y_b[s],50,50,"blue");
}
str=str+"</svg>";
$("#memo").html(str);
}
最終更新:2015年03月01日 13:44