アットウィキロゴ

eru

var x = new Array();
var y = new Array();
var a = new Array();
var life = new Array();
var dir = new Array();
var number_dir = new Array();
 
function sample(){
 
tx=0;
for(s=1;s<6;s++){
for(sx=1;sx<6;sx++){
tx=tx+1;
x[tx]=s;
y[tx]=sx;
}}
 
for(s=1;s<26;s++){
dir[s]=new Array();
}
 
for(s=1;s<26;s++){
life[s]=new Array();
}
 
 
for(s=1;s<26;s++){
a[s]=new Array();
}
 
 
for (s = 1; s < 26; s++) {
for (sx = 1; sx < 11; sx++) {
a[s][sx] = s;
life[s][sx] = 100;
}}
 
 
 
for(s=1;s<26;s++){
t=0;    
for(s1=-1;s1<2;s1++){
for(s2=-1;s2<2;s2++){
tx=search(x[s]+s1,y[s]+s2);
if(tx==s)tx=0;  
if(tx>0)t=t+1;
if(tx>0)dir[s][t]=tx;    
}}
number_dir[s]=t;
}
 
var timer;
var delay = 1000;
 
var loop = function () {
 
    for (s = 1; s < 26; s++) {
        for (sx = 1; sx < 11; sx++) {
            move(s, sx);
        } 
         for (sx = 1; sx < 11; sx++) {
if(life[s][sx]>50)game(s, sx);
        } 
 
 
    }
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
}
 
 
function game(s1,s2){
 
    a1 = a[s1][s2];
 
    c1 = 0;
     for (tx = 1; tx < 11; tx++) {
            h = 0;
            if (a[s1][tx] == a1) h = h + 1;
            if (life[s1][tx]>50) h = h + 1;
        if (h == 2) c1 = c1 + 1;
     } 
 
    c2 = 0;
    for (t = 1; t < 26; t++) {
        for (tx = 1; tx < 11; tx++) {
            h = 0;
            if (a[t][tx] == a1) h = h + 1;
            if (life[t][tx]>50) h = h + 1;
            if (s1 == t) h = 0;
        if (h == 2) c2 = c2 + 1;
     } 
    }
 
 
 
    fight(a1, s1, c1, c2);
 
 
}
 
function fight(a1,sx1,c1,c2){
 
m1=(c1 + c2) * Math.random();
m2 = 2;
if (m1 < c1) m2 = 1;
 
 
if (m2 == 1) alpha(a1,sx1);
if (m2 == 2) beta(a1,sx1);
 
 
}
 
function beta(a1, sx1) {
 
for (tx = 1; tx < 11; tx++) {
            h = 0;
            if (a[sx1][tx] == a1) h = h + 1;
            if (life[sx1][tx]>50) h = h + 1;
        if (h == 2)life[sx1][tx]=0;
     } 
 
 
}
 
 
function alpha(a1,sx1){
 
    var t, tx,h;
 
    for (t = 1; t < 26; t++) {
        for (tx = 1; tx < 11; tx++) {
            h = 0;
            if (a[t][tx] == a1) h = h + 1;
            if (life[t][tx]>50) h = h + 1;
            if (sx1 == t) h = 0;
        if (h == 2)life[t][tx]=0 ;
     } 
    }
 
 
 
}
 
 
function paint(){
 
var sub=new svgpaint();
 
str="<svg width=\"500\" height=\"500\">";
 
for(t=1;t<26;t++){
for(s=1;s<11;s++){
sx = a[t][s];
colx = "blue";
if (t == 1)colx="red";
if (life[t][s] > 50)str=str+sub.rect(100*x[sx]-100,100*y[sx]-100,100,100,colx);   
}}
 
str=str+"</svg>";
 
$("#memo").html(str);
 
}
 
 
function move(s1,s2){
 
    t1 = a[s1][s2];
    n1 = number_dir[t1] * Math.random();
    n2 = Math.floor(n1) + 1;
    a[s1][s2] = dir[t1][n2];
}
 
 
 
 
 
function search(x1,y1){
 
    var s,sx;
    sx=0;
    for (s = 1; s < 26; s++) {
        h = 0;
        if (x[s] == x1) h = h + 1;
        if (y[s] == y1) h = h + 1;
        if (h == 2) sx = s;
    }
    return sx;
 
}
 
最終更新:2015年06月12日 06:01