アットウィキロゴ

ghf

var x = new Array();
var y = new Array();
var pos = new Array();
var area = new Array();
var life = new Array();
var dir = new Array();
var number_dir = new Array();
var power = new Array();
var month;
 
 
function sample(){
 
for(s=1;s<26;s++){
dir[s]=new Array();
life[s]=new Array();
pos[s]=new Array();
}
 
 
faststep();
 
var timer;
var delay = 1000;
 
month = 1;
 
var loop = function () {
 
    month = month + 1;
    if (month > 12) change();
    if (month > 12) month = 1;
 
 
    for (tr = 1; tr < 26; tr++) {
        step(tr);
        game(tr);
    }
 
    check();
 
    delta();
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
}
function change() {
 
 var s, sx, tx;
 
 
    for (s = 1; s < 26; s++) {
        power[s] = 0;
 
    }
 
    for (s = 1; s < 26; s++) {
        sx = area[s];
        power[sx] = power[sx] + 100;
    }
    power[1] = 1000;
 
    for (s = 1; s < 26; s++) {
    for (sx = 1; sx < 6; sx++) {
        if (area[s] == s) life[s][sx] = 100;
        } 
    }
 
 
 
}
 
function check(){
 
    var s, sx, tx;
 
    for (s = 1; s < 26; s++) {
        for (sx = 1; sx < 6; sx++) {
           tx = 0;
            if (life[s][sx] > 50) tx = pos[s][sx];
          if (life[s][sx] > 50)area[tx] = s;
        } 
    }
 
 
}
 
function delta(){
 
for(s=1;s<26;s++){
    h = 0;
if(area[s]==s)h=100;    
for(sx=1;sx<6;sx++){
if(h<50)life[s][sx]=0;    
}
}
 
 
 
 
 
 
}
 
 
function step(s1){
 
  for(n=2;n<6;n++){
  move(s1,n);    
  }
 
 
}
function game(s1){
 
for(s2=1;s2<6;s2++){
subgame(s1,s2);    
}
 
 
 
}
 
function subgame(s1,s2){
 
    a1 = pos[s1][s2];
 
    c1 = 0;
     for (tx = 1; tx < 6; tx++) {
            h = 0;
            if (pos[s1][tx] == a1) h = h + 1;
            if (life[s1][tx]>50) h = h + 1;
        if (h == 2) c1 = c1 + power[s1];
     } 
 
    c2 = 0;
    for (t = 1; t < 26; t++) {
        for (tx = 1; tx < 6; tx++) {
            h = 0;
            if (pos[t][tx] == a1) h = h + 1;
            if (life[t][tx]>50) h = h + 1;
            if (s1 == t) h = 0;
        if (h == 2) c2 = c2 + power[t];
     } 
    }
 
    h = 0;
    if (c1 > 0) h = h + 1;
    if (c2 > 0) h = h + 1;
    if(h==2)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 < 6; tx++) {
            h = 0;
            if (pos[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 < 6; tx++) {
            h = 0;
            if (pos[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 move(s1,n){
 
    var t1 = pos[s1][n];
    var n1 = number_dir[t1] * Math.random();
    var n2 = Math.floor(n1) + 1;
    pos[s1][n] = dir[t1][n2];
}
 
 
 
function paint(){
 
var sub=new svgpaint();
 
str="<svg width=\"500\" height=\"500\">";
 
for(t=1;t<26;t++){
   str=str+sub.rect(100*x[t]-100,100*y[t]-100,100,100,"blue");
if (area[t] == 1)str=str+sub.rect(100*x[t]-100,100*y[t]-100,100,100,"red");
} 
 
 
 
str=str+"</svg>";
 
$("#memo").html(str);
 
}
 
 
function faststep(){
 
var s, sx, tx;
 
tx=0;
for(s=1;s<6;s++){
for(sx=1;sx<6;sx++){
tx=tx+1;
x[tx]=s;
y[tx]=sx;
}}
 
var t, s1, s2;
 
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;
}    
 
for(s=1;s<26;s++){
area[s]=s;
power[s] = 100;
}
power[1] = 1000;
 
for(s=1;s<26;s++){
for(sx=1;sx<6;sx++){
pos[s][sx]=s;
life[s][sx] = 100;
}}
 
}
 
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月13日 05:11