アットウィキロゴ

fushimi

var x = new Array();
var y = new Array();
var dir = new Array();
var number_dir = new Array();
var a=new Array();
var b=new Array();
var life_a=new Array(); 
var life_b=new Array(); 
 
function sample(){
 
faststep();
 
 
for(s=1;s<101;s++){
a[s] = 1;
b[s] = 100;
life_a[s] = 100;
life_b[s] = 100;
}
 
var timer;
var delay = 1000;
 
var loop = function () {
 
 
 
    move();
 
    move_a();
 
    move_b();
 
    game();
 
    check();
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
 
}
 
function check(){
    z = 0;
    if (life_a[1] < 50) z = 100;
    if (life_b[1] < 50) z = 100;
 
    if(z>50){
 
for(s=1;s<101;s++){
a[s] = 1;
b[s] = 100;
life_a[s] = 100;
life_b[s] = 100;
}
 
 
    }
 
 
}
 
 
 
function game(){
 
var c1=new Array();
var c2=new Array();
 
for(s=1;s<101;s++){
c1[s]=0;
c2[s] = 0;
}
 
for(s=1;s<101;s++){
sx = a[s];
if(life_a[s]>50)c1[sx]=100;
sx = b[s];
if(life_b[s]>50)c2[sx]=100;
}
 
 
for(a1=1;a1<101;a1++){
    h = 0;
    if (c1[a1] > 50) h = h + 1;
     if (c2[a1] > 50) h = h + 1;
     if (h == 2) fight(a1);
}
 
 
}
 
function fight(a1){
 
    p1 = 0;
    p2 = 0;
 
    for(s=1;s<101;s++){
        h = 0;
    if(life_a[s]>50)h=h+1;
    if(a[s]==a1)h=h+1;
    if(h==2)p1=p1+1;    
    }
 
    for(s=1;s<101;s++){
        h = 0;
    if(life_b[s]>50)h=h+1;
    if(b[s]==a1)h=h+1;
    if(h==2)p2=p2+1;    
    }
 
 
    mode = 1;
    n1=(p1 + p2) * Math.random();
    if (n1 > p1) mode = 2;
 
 if (mode == 1) alpha(a1);
 if (mode == 2) beta(a1);
 
 
} 
 
 
function alpha(a1){
 
for(s=1;s<101;s++){
      h = 0;
    if(life_b[s]>50)h=h+1;
    if(b[s]==a1)h=h+1;
    if(h==2)life_b[s]=0;    
 
}   
 
 
 
}
 
function beta(a1){
 
for(s=1;s<101;s++){
      h = 0;
    if(life_a[s]>50)h=h+1;
    if(a[s]==a1)h=h+1;
    if(h==2)life_a[s]=0;    
 
}   
 
 
 
}
 
 
 
 
function move(){
 
    for(s=1;s<101;s++){
        sx = a[s];
        n1 = number_dir[sx] * Math.random();
        n2 = Math.floor(n1) + 1;
        a[s] = dir[sx][n2];
     }
 
     for(s=1;s<101;s++){
        sx = b[s];
        n1 = number_dir[sx] * Math.random();
        n2 = Math.floor(n1) + 1;
        b[s] = dir[sx][n2];
     }
 
 
 
 
}
 
 
 
 
function faststep(){
 
tx=0;
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
tx=tx+1;
x[tx]=s;
y[tx]=sx;
}}
 
for(t=1;t<101;t++){
dir[t] = new Array();
} 
 
for(t=1;t<101;t++){
    tx = 0;
for(s1=-1;s1<2;s1++){
for(s2=-1;s2<2;s2++){
    x1 = x[t] + s1;
    y1 = y[t] + s2;
    sx = search(x1, y1);
  if(sx==t)sx=0;
    if (sx > 0) tx = tx + 1;
    if (sx > 0) dir[t][tx] = sx;
}}
number_dir[t] = tx;
} 
 
 
}
 
function search(x1,y1){
 
    var s,sx,h;
    sx=0;
    for (s = 1; s < 101; s++) {
        h = 0;
        if (x[s] == x1) h = h + 1;
        if (y[s] == y1) h = h + 1;
        if (h == 2) sx = s;
    }
    return sx;
 
}
 
 
 
 
function paint(){
 
 var sub=new svgpaint();
 
str="<svg width=\"500\" height=\"500\">";
 
for(s=1;s<101;s++){    
str=str+sub.rect(50*x[s]-50,50*y[s]-50,50,50,"green");
}
for(s=1;s<101;s++){
b1 = a[s];
if(life_a[s]>50)str=str+sub.rect(50*x[b1]-50,50*y[b1]-50,50,50,"blue");
}
 
 for(s=1;s<101;s++){
b1 = b[s];
if(life_b[s]>50)str=str+sub.rect(50*x[b1]-50,50*y[b1]-50,50,50,"red");
}
str=str+"</svg>";
 
$("#memo").html(str);   
 
}
 
function move_a(){
 
 
    for(s=1;s<101;s++){
        sx = a[s];
        c = b[1];
        n2 = 1;
        mind = 1000;
      for(nx=1;nx<number_dir[sx]+1;nx++){
       n1= dir[sx][nx];
       d1 = (x[n1] - x[c]) * (x[n1] - x[c]) + (y[n1] - y[c]) * (y[n1] - y[c]);
       if (d1 < mind) n2 = nx;
       if (d1 < mind) mind = d1;
}
a[s]=dir[sx][n2];     
}
 
}
 
function move_b(){
 
 
    for(s=1;s<101;s++){
        sx = b[s];
        c = a[1];
 
        n2 = 1;
        mind = 1000;
      for(nx=1;nx<number_dir[sx]+1;nx++){
       n1= dir[sx][nx];
       d1 = (x[n1] - x[c]) * (x[n1] - x[c]) + (y[n1] - y[c]) * (y[n1] - y[c]);
       if (d1 < mind) n2 = nx;
       if (d1 < mind) mind = d1;
}
b[s]=dir[sx][n2];     
}
 
}
最終更新:2015年06月18日 17:48