アットウィキロゴ

lifex65

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();
 
function sample() {
 
    for (s = 1; s < 11; s++) {
        a[s] = 1;
        b[s] = 100;
    }
 
    for (t = 1; t < 26; t++) {
dir[t] = new Array();
    }
 
    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++) {
        tx = 0;
        dir[t] = new Array();
        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;
    }
 
    var timer;
    var delay = 100;
 
 
    var loop = function () {
 
        for(s=1;s<11;s++){
 
            move_a(s);
 
            move_b(s);
 
        }
 
 
        for (a1 = 1; a1 < 101; a1++) {
        game_a(a1);
        }
 
        paint();
 
        clearTimeout(timer);
        timer = setTimeout(loop, delay);
    }
 
    loop();
 
} function paint() {
 
    var sub = new svgpaint();
 
    str = "<svg width=\"500\" height=\"500\">";
 
    for (t = 1; t < 11; t++) {
        s = a[t];
        str = str + sub.rect(50 * x[s] - 50, 50 * y[s] - 50, 50, 50, "red");
    }
 
    for (t = 1; t < 11; t++) {
        s = b[t];
        str = str + sub.rect(50 * x[s] - 50, 50 * y[s] - 50, 50, 50, "blue");
    }
 
    str = str + "</svg>";
 
    $("#memo").html(str);
 
}
 
 
function game_a(a1) {
 
 
    c1 = 0;
    for (s = 1; s < 11; s++) {
        if (a[s] == a1) c1 = c1 +1;
    }
 
 
    c2 = 0;
    for (s = 1; s < 11; s++) {
        s1 = b[s];
        for (sx = 1; sx < number_dir[s1] + 1; sx++) {
            if (dir[s1][sx] == a1) c2 = c2 + 1;
        }
    }
 
    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 < 11; s++) {
        h = 0;
        if (a[s] == a1) h = h + 1;
        if (m2 == 2) h = h + 1;
        if (h == 2) a[s] = 1;
    }
 
 
    c2 = 0;
    for (s = 1; s < 11; s++) {
        s1 = b[s];
        for (sx = 1; sx < number_dir[s1] + 1; sx++) {
            if (dir[s1][sx] == a1) b[s]=100;
        }
    }
 
 
}
 
 
 
 
function move_a(s) {
 
 
 
    s1 = a[s];
    for (sx = 1; sx < number_dir[s1] + 1; sx++) {
        n1 = number_dir[s1]*Math.random();
        n2 = Math.floor(n1) + 1;
        s2=dir[s1][n2];
    }
 
    ch = 0;
    for (sx = 1; sx <11; sx++) {
        if (a[sx] == s2) ch = 100;
        if (b[sx] == s2) ch = 100;
    }
 
    if (ch < 50) a[s] = s2;
 
 
 
 
}
 
function move_b(s) {
 
 
 
    s1 = b[s];
    for (sx = 1; sx < number_dir[s1] + 1; sx++) {
        n1 = number_dir[s1] * Math.random();
        n2 = Math.floor(n1) + 1;
        s2 = dir[s1][n2];
    }
 
    ch = 0;
    for (sx = 1; sx < 11; sx++) {
        if (a[sx] == s2) ch = 100;
        if (b[sx] == s2) ch = 100;
    }
 
    if (ch < 50) b[s] = s2;
 
 
 
 
}
 
 
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;
 
}
 
最終更新:2015年06月21日 15:12