Commit f6e36954 authored by Tomás Teijeiro Campo's avatar Tomás Teijeiro Campo

Changes in the distributions for the generation of the initial populatio

parent 2d0a083d
// Game global config vars [MOVE TO SETTINGS]
var WALL_MARGIN = 80;
var DIR_CHANGE_MIN_TIME = 10;
var DIR_CHANGE_MIN_TIME = 0;
var SHOOT_DELAY = 100;
var MIN_INVADERS = 4;
var INITIAL_INVADERS = 6;
......
var invadersApp = invadersApp || {};
// Port of python random.gammavariate
function gammavariate(alpha, beta) {
SG_MAGICCONST = 1.0 + Math.log(4.5);
ainv = Math.sqrt(2.0 * alpha - 1.0);
bbb = alpha - 1.3862943611198906;
ccc = alpha + ainv;
while (1) {
u1 = Math.random();
if (u1 <= 1e-7 || u1 >= .9999999) {continue;}
u2 = 1.0 - Math.random();
v = Math.log(u1/(1.0-u1))/ainv;
x = alpha*Math.exp(v);
z = u1*u1*u2;
r = bbb+ccc*v-x;
if (r + SG_MAGICCONST - 4.5*z >= 0.0 || r >= Math.log(z)) {
return x * beta;
}
}
}
function bound_value(v, min_v, max_v) {
return Math.min(Math.max(min_v, v), max_v)
}
// Extended sprite object for Invaders
invadersApp.Invader = function (ctx, genes, x, y) {
......@@ -22,6 +47,13 @@ invadersApp.Invader = function (ctx, genes, x, y) {
if (genes[gen] < min) genes[gen] = min;
if (genes[gen] > max) genes[gen] = max;
}
//TODO guarrada para comprobar a influencia da primeira xeración
genes['scale'] = bound_value(gammavariate(4, 0.5)+1, 1, 7);
genes['alpha'] = chance.integer({min: 20, max: 255});
genes['xvelocity'] = 100*bound_value(gammavariate(2, 0.4), 0.01, 5);
genes['yvelocity'] = 100*bound_value(gammavariate(2, 0.3), 0.01, 5);
genes['x_prob_change_dir'] = chance.floating({min: 0.01, max: 0.05});
genes['y_prob_change_dir'] = chance.floating({min: 0.01, max: 0.05});
return genes;
}();
......
......@@ -12,24 +12,24 @@
"mean": 200
},
"xvelocity": {
"min": 0,
"max": 300,
"mean": 30
"min": 1,
"max": 500,
"mean": 200
},
"yvelocity": {
"min": 0,
"max": 300,
"mean": 30
"min": 1,
"max": 500,
"mean": 200
},
"x_prob_change_dir": {
"min": 0.00,
"max": 0.10,
"mean": 0.01
"min": 0.01,
"max": 0.07,
"mean": 0.03
},
"y_prob_change_dir": {
"min": 0.00,
"max": 0.10,
"mean": 0.01
"min": 0.0,
"max": 0.07,
"mean": 0.03
}
},
"mutation_probability": 0.1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment