アットウィキロゴ

jhgpj

var life_a = new Array();
var life_b = new Array();
var a = new Array();
var b = new Array();
var x = new Array();
var y = new Array();
var area = new Array();
var power_a, power_b;
var month;
 
function sample(){
 
    tx=0;
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
tx=tx+1;
x[tx]=s;
y[tx]=sx;
}}
 
 
    delta();
 
   var timer;
var delay = 100;
 
month = 0;
 
var loop = function () {
 
    month = month + 1;
    if (month >100) faststep();
    if (month >100) month = 0;
    move_a();
    move_b();
 
    for (a = 1; a < 101; a++) {
        game(a);
    }
 
 
    check();
 
    if (area[1] == 2) delta();
      if (area[100] == 1) delta();
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
}
 
function delta(){
 
for(s=1;s<101;s++){
area[s]=0;    
}
 
area[1] = 1;
area[100] = 2;
 
for(s=1;s<5;s++){
a[s]=1;
life_a[s]=100;    
b[s]=100;
life_b[s]=100;  
}
 
power_a = 100;
power_b = 100;
 
 
 
}
 
function paint(){
 
var sub=new svgpaint();
 
str="<svg width=\"500\" height=\"500\">";
for(s=1;s<101;s++){
if(area[s]==1)str=str+sub.rect(50*x[s]-50,50*y[s]-50,50,50,"blue"); 
if(area[s]==2)str=str+sub.rect(50*x[s]-50,50*y[s]-50,50,50,"red"); 
}
str=str+"</svg>";
 
$("#memo").html(str);
 
}
 
 
function game(a1){
 
 
    c1 = 0;
for(s=1;s<5;s++){
if(a[s]==a1)c1=c1+power_a;    
}    
 
 
c2 = 0;
for(s=1;s<5;s++){
if(b[s]==a1)c2=c2+power_b;    
}
 
h=0;
if (c1 > 0) h = h + 1;
if (c2 > 0) h = h + 1;
if (h == 2) fight(a1,c1, c2);
 
}
 
function fight(a1,c1,c2){
 
m2 = 1;
m1=(c1+c2)*Math.random();
if(m1>c1)m2=2;
 
for(s=1;s<5;s++){
h=0;
if(a[s]==a1)h=h+1;
if(m2==2)h=h+1;
if(h==2)life_a[s]=0;  
}
 
for(s=1;s<5;s++){
h=0;
if(b[s]==a1)h=h+1;
if(m2==1)h=h+1;
if(h==2)life_b[s]=0;  
}
 
 
} 
 
 
 
 
function check(){
 
for(s=1;s<5;s++){
sx = a[s];
if(life_a[s]>50)area[sx]=1;
}
 
 
for(s=1;s<5;s++){
sx = b[s];
if(life_b[s]>50)area[sx]=2;
}
 
 
}
 
function search(x1,y1){
 
    var s,sx;
    sx=1;
    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 move_a(){
 
    for (s = 1; s < 5; s++) {
        dx = -1;
        if (Math.random() > 0.5) dx = 1;
        dy = -1;
        if (Math.random() > 0.5) dy = 1;
        s1 = a[s];
        x1=x[s1] + dx;
        y1 = y[s1] + dy;
 
        if (x1> 10) x1 = 10;
     if (y1> 10) y1 = 10;
      if (x1< 1) x1 = 1;
     if (y1<1) y1 = 1;
     a[s] = search(x1, y1);
 
    }
 
 
 
 
}
 
 
function move_b(){
 
    for (s = 1; s < 5; s++) {
        dx = -1;
        if (Math.random() > 0.5) dx = 1;
        dy = -1;
        if (Math.random() > 0.5) dy = 1;
        s1 = b[s];
        x1=x[s1] + dx;
        y1 = y[s1] + dy;
 
        if (x1> 10) x1 = 10;
     if (y1> 10) y1 = 10;
      if (x1< 1) x1 = 1;
     if (y1<1) y1 = 1;
     b[s] = search(x1, y1);
 
    }
 
 
 
 
}
 
function faststep(){
 
 
 
    c1 = 0;
    c2=0;
for(s=1;s<101;s++){
if (area[s] == 1) c1 = c1 + 1;
if (area[s] == 2) c2 = c2 + 1;
}
 
power_a = 100 * c1;
power_b = 100 * c2;
 
for(s=1;s<5;s++){
    life_a[s] = 100;
    a[s] = 1;
 
}
 
for(s=1;s<5;s++){
    life_b[s] = 100;
    b[s] = 100;
 
}
 
 
 
 
 
 
 
}
 
最終更新:2015年06月11日 02:58