var x=new Array();
var y=new Array();
var m=new Array();
var alpha;
var w;
function sample(){
alpha=0.5;
w=0.3;
for(s=1;s<101;s++){
x[s]=0;
m[s]=100;
}
x[1]=1;
x[2]=1;
ex=50;
d=0;
var timer;
var delay = 1000;
var loop = function () {
n=count();
c=n*30;
yd=ex+c+d;
select(yd);
ys=100*n;
if(yd>ys)yd=ys;
d=alpha*yd;
for(s=1;s<100;s++){
if(x[s]==1)m[s]=m[s]+((1-alpha)*y[s]-30);
}
r1=rate(yd);
if(r1>80)plus();
check();
$("#memo").html(n+","+r1);
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function check(){
for(s=1;s<100;s++){
h=0;
if(x[s]==1)h=h+1;
if(m[s]<0)h=h+1;
if(h==2)x[s]=0;
if(h==2)m[s]=100;
}
}
function plus(){
f1=0;
for(s=1;s<100;s++){
h=0;
if(f1==0)h=h+1;
if(x[s]==0)h=h+1;
if(h==2)x[s]=1;
if(h==2)f1=100;
}
}
function rate(yd){
var ys;
ys=0;
for(s=1;s<100;s++){
if(x[s]==1)ys=ys+100;
}
r=100*yd/ys
return r;
}
function select(yd){
var p1=yd;
var s;
for(s=1;s<101;s++){
y[s]=0;
}
for(s=1;s<101;s++){
h=0;
if(x[s]==1)h=h+1;
if(p1<100)h=h+1;
if(p1>0)h=h+1;
if(h==3)y[s]=p1;
if(h==3)p1=0;
h=0;
if(x[s]==1)h=h+1;
if(p1>99)h=h+1;
if(h==2)y[s]=100;
if(h==2)p1=p1-100;
}
}
function count(){
n1=0;
for(s=1;s<100;s++){
if(x[s]==1)n1=n1+1;
}
return n1;
}
最終更新:2015年12月27日 04:09