[401] | 1 | //size versus energy
|
---|
| 2 | //real proportions
|
---|
| 3 |
|
---|
[422] | 4 | function init_chambers()
|
---|
| 5 | {
|
---|
| 6 | colors = ["1.0,1.0,0.0","1.0,0.5,0.0"];
|
---|
[432] | 7 | chambers = [ ["0.0,0.0,0.0,", //coiled
|
---|
[430] | 8 | "1.08020961284637, -0.0597195439040661, -0.0393781512975693,",
|
---|
| 9 | "1.08020961284637, -0.0597195439040661, -0.0393781512975693,",
|
---|
| 10 | "0.615013539791107, 0.778662621974945, 0.535521030426025,",
|
---|
| 11 | "0.488581955432892, 0.826426684856415, -0.381044268608093,",
|
---|
| 12 | "0.732419908046722, -0.0084995785728097, -1.02214300632477,",
|
---|
| 13 | "1.35288727283478, 0.875738024711609, -1.03719782829285,",
|
---|
| 14 | "0.342692613601685, 0.938660383224487, -1.45657968521118,",
|
---|
| 15 | "1.0958571434021, 0.316927701234818, -1.813929438591,",
|
---|
| 16 | "0.903768002986908, 1.11856341362, -2.53161096572876,",
|
---|
[432] | 17 | "0.21014116704464, 0.295340299606323, -2.45328187942505,"],
|
---|
| 18 | ["0.0,0.0,0.0,", //longitudal
|
---|
| 19 | "0.98089325428009, 0.00591040402650833, 0.00389722990803421,",
|
---|
| 20 | "1.90962779521942, -0.256769120693207, -0.16194811463356,",
|
---|
| 21 | "2.63965249061584, -0.727959632873535, -0.609036147594452,",
|
---|
| 22 | "3.17575979232788, -1.34843015670776, -1.14828503131866,",
|
---|
| 23 | "3.55273032188416, -2.22369408607483, -1.3917418718338,",
|
---|
| 24 | "3.64916682243347, -3.11888360977173, -1.01666414737701,",
|
---|
| 25 | "3.50461649894714, -3.84039807319641, -0.377427101135254,",
|
---|
| 26 | "3.15921688079834, -4.50001525878906, 0.261153399944305,",
|
---|
| 27 | "2.51528453826904, -5.16421365737915, 0.59241509437561,"]];
|
---|
[422] | 28 | }
|
---|
[401] | 29 |
|
---|
[422] | 30 | function createForamGenotype(gen, species, chamber_num)
|
---|
[401] | 31 | {
|
---|
[422] | 32 | var rad = getProperty(gen, "chamber_proculus");
|
---|
[430] | 33 | var geno = "//0\np:" + chambers[species][0] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ", rz=3.14159265358979,vr=" + colors[gen];
|
---|
[401] | 34 |
|
---|
[422] | 35 | chamber_num = Math.min(chamber_num, chambers[species].size - 1);
|
---|
| 36 |
|
---|
| 37 | for (var i = 0; i < chamber_num; i++)
|
---|
| 38 | {
|
---|
[432] | 39 | rad = getProperty(gen, "chamber_proculus") + getProperty(gen, "chamber_difference") * (i + 1);
|
---|
[430] | 40 | geno += "\n" + "p:" + chambers[species][i+1] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ",vr=" + colors[gen];
|
---|
[422] | 41 | }
|
---|
| 42 |
|
---|
| 43 | for (var i = 0; i < chamber_num; i++)
|
---|
| 44 | {
|
---|
| 45 | geno += "\n" + "j:"+ i +", "+ (i+1) +", sh=1";
|
---|
| 46 | }
|
---|
[430] | 47 |
|
---|
[432] | 48 | if (species == 0) geno += "\nn:p=0,d=\"S\"";
|
---|
[422] | 49 |
|
---|
| 50 | return geno;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | function setGenotype(mode)
|
---|
| 54 | {
|
---|
[476] | 55 | if (mode->opt == 0) //initial
|
---|
[422] | 56 | {
|
---|
[476] | 57 | mode->cr.data->genes = {"min_repro_energies" : [max_chamber_energ[0][getProperty(0, "min_repro_energ")], max_chamber_energ[1][getProperty(1, "min_repro_energ")]], "hibernation" : mode->species};
|
---|
| 58 | mode->cr.data->lifeparams = {"max_energy_level" : getProperty(0,"energies0"), "gen" : 0, "hibernated" : 0, "species" : mode->species, "reproduce" : 0, "dir" : randomDir()};
|
---|
[422] | 59 | }
|
---|
[476] | 60 | else if (mode->opt == 1) //child
|
---|
[422] | 61 | {
|
---|
[476] | 62 | mode->cr.data->lifeparams = {"max_energy_level" : getProperty(1 - mode->parent_lifeparams->gen,"energies0"), "gen" : 1 - mode->parent_lifeparams->gen, "hibernated" : 0, "species" : mode->parent_lifeparams->species, "reproduce" : 0, "dir" : randomDir()};
|
---|
| 63 | mode->cr.data->genes = mode->parent_genes;
|
---|
[422] | 64 | }
|
---|
| 65 | else //grow
|
---|
| 66 | {
|
---|
[476] | 67 | mode->cr.data->genes = mode->parent_genes;
|
---|
| 68 | mode->cr.data->lifeparams = mode->parent_lifeparams;
|
---|
[422] | 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | function reproduce_haploid(parent, parent2, clone)
|
---|
| 73 | {
|
---|
[476] | 74 | var number, energy0, new_genes, gen;
|
---|
[422] | 75 | if (clone == 1)
|
---|
| 76 | {
|
---|
| 77 | energy0 = getProperty(0,"energies0");
|
---|
[430] | 78 | number = (( 1 - getProperty(1, "e_repro_cost")) * parent.energy) / energy0;
|
---|
[476] | 79 | new_genes = parent.data->genes;
|
---|
| 80 | parent.data->lifeparams->gen = 1 - parent.data->lifeparams->gen; //because of reversal of "gen" in createOffspring function
|
---|
| 81 | gen = parent.data->lifeparams->gen;
|
---|
[422] | 82 | }
|
---|
| 83 | else
|
---|
| 84 | {
|
---|
| 85 | energy0 = getProperty(1,"energies0");
|
---|
[476] | 86 | number = (((1 - getProperty(parent.data->lifeparams->gen, "e_repro_cost")) * parent.energy) + ((1 -(getProperty(parent.data->lifeparams->gen, "e_repro_cost"))) * parent2.energy)) / energy0;
|
---|
| 87 | new_genes = [parent.data->genes, parent2.data->genes];
|
---|
| 88 | gen = 1 - parent.data->lifeparams->gen;
|
---|
[422] | 89 | }
|
---|
| 90 |
|
---|
[430] | 91 | Simulator.print("haploid number of offspring: " + number + " energ0: " + energy0);
|
---|
[422] | 92 |
|
---|
[418] | 93 | for (var j = 0; j < number; j++)
|
---|
[401] | 94 | {
|
---|
[476] | 95 | createOffspring(createForamGenotype(gen, parent.data->lifeparams->species, 0), energy0, new_genes, parent.data->lifeparams);
|
---|
[401] | 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[418] | 99 | function reproduce_diploid(parent)
|
---|
[401] | 100 | {
|
---|
[422] | 101 | var energy0 = getProperty(0,"energies0");
|
---|
[476] | 102 | var number = ((1 - (getProperty(parent.data->lifeparams->gen, "e_repro_cost"))) * parent.energy) / energy0;
|
---|
[422] | 103 |
|
---|
[430] | 104 | Simulator.print("diploid number of offspring: " + number+ " energ0: " + energy0);
|
---|
[422] | 105 |
|
---|
[418] | 106 | for (var j = 0; j < number / 2; j++)
|
---|
[401] | 107 | {
|
---|
[418] | 108 | var crossed = 0;
|
---|
| 109 | //crossover
|
---|
| 110 | if (Math.rnd01 < ExpParams.crossprob)
|
---|
| 111 | {
|
---|
[422] | 112 | crossover(parent, "min_repro_energies");
|
---|
[418] | 113 | crossed = 1;
|
---|
| 114 | }
|
---|
[401] | 115 |
|
---|
[418] | 116 | for (var k = 0; k < 2; k++)
|
---|
[404] | 117 | {
|
---|
[476] | 118 | createOffspring(createForamGenotype(1 - parent.data->lifeparams->gen, parent.data->lifeparams->species, 0), energy0, parent.data->genes[0], parent.data->lifeparams);
|
---|
[404] | 119 | }
|
---|
| 120 |
|
---|
[418] | 121 | //reverse of crossover for fossilization
|
---|
| 122 | if (crossed == 1)
|
---|
[401] | 123 | {
|
---|
[422] | 124 | crossover(parent, "min_repro_energies");
|
---|
[418] | 125 | crossed = 0;
|
---|
[401] | 126 | }
|
---|
[418] | 127 |
|
---|
[401] | 128 | }
|
---|
[404] | 129 | }
|
---|
| 130 |
|
---|
[422] | 131 | function reproduce_parents(species)
|
---|
[404] | 132 | {
|
---|
[418] | 133 | var parent1 = null;
|
---|
| 134 | var parent2 = null;
|
---|
| 135 | var pop = Populations[0];
|
---|
| 136 | for (var i = pop.size-1; i >= 0; i--)
|
---|
[401] | 137 | {
|
---|
[476] | 138 | if (pop[i].data->lifeparams->reproduce == 1 && pop[i].data->lifeparams->species == species)
|
---|
[418] | 139 | {
|
---|
[476] | 140 | if ((pop[i].data->lifeparams->gen==1) || ((pop[i].data->lifeparams->gen==0) && ExpParams.stress == 0))
|
---|
[401] | 141 | {
|
---|
[422] | 142 | continue;
|
---|
[401] | 143 | }
|
---|
[418] | 144 | else if (parent1 == null)
|
---|
[401] | 145 | {
|
---|
[418] | 146 | parent1 = pop[i];
|
---|
[401] | 147 | }
|
---|
[418] | 148 | else if (parent2 == null)
|
---|
| 149 | {
|
---|
| 150 | parent2 = pop[i];
|
---|
| 151 | }
|
---|
[430] | 152 | if (parent1 != null && parent2 != null)
|
---|
[418] | 153 | {
|
---|
[422] | 154 | reproduce_haploid(parent1, parent2, 0);
|
---|
| 155 | print_repro_info(parent1);
|
---|
| 156 | print_repro_info(parent2);
|
---|
[418] | 157 | pop.kill(parent1);
|
---|
| 158 | pop.kill(parent2);
|
---|
| 159 | parent1 = null;
|
---|
| 160 | parent2 = null;
|
---|
[430] | 161 | }
|
---|
[418] | 162 | }
|
---|
[401] | 163 | }
|
---|
[422] | 164 | }
|
---|
| 165 |
|
---|
| 166 | function readyToRepro(cr)
|
---|
| 167 | {
|
---|
| 168 | var reproduced = 1;
|
---|
| 169 |
|
---|
| 170 |
|
---|
[476] | 171 | if (cr.data->lifeparams->gen == 1)
|
---|
[422] | 172 | {
|
---|
| 173 | reproduce_diploid(cr);
|
---|
[401] | 174 | }
|
---|
| 175 |
|
---|
[422] | 176 | else if (ExpParams.stress == 0)
|
---|
[401] | 177 | {
|
---|
[422] | 178 | reproduce_haploid(cr, null, 1);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | else
|
---|
| 182 | {
|
---|
| 183 | if (cr.signals.size == 0)
|
---|
[401] | 184 | {
|
---|
[476] | 185 | cr.signals.add("repro"+cr.data->lifeparams->species);
|
---|
[422] | 186 | cr.signals[0].power = 1;
|
---|
[401] | 187 | }
|
---|
[422] | 188 | reproduced = 0;
|
---|
[476] | 189 | cr.data->lifeparams->reproduce = 1;
|
---|
[401] | 190 | }
|
---|
[422] | 191 |
|
---|
| 192 | if (reproduced == 1)
|
---|
| 193 | {
|
---|
| 194 | print_repro_info(cr);
|
---|
| 195 | Populations[0].kill(cr);
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | return reproduced;
|
---|
[401] | 199 | }
|
---|
| 200 |
|
---|
[422] | 201 | function print_repro_info(cr)
|
---|
[421] | 202 | {
|
---|
[476] | 203 | Simulator.print("Reproduced " + cr.data->lifeparams->gen + " of species " + cr.data->lifeparams->species + " energy: " + cr.energy);
|
---|
[422] | 204 | }
|
---|
[421] | 205 |
|
---|
[430] | 206 |
|
---|
| 207 |
|
---|
[422] | 208 | function foramReproduce(cr)
|
---|
| 209 | {
|
---|
| 210 | var properEnergy = 0;
|
---|
| 211 | var reproduced = 0;
|
---|
| 212 |
|
---|
[476] | 213 | if (cr.data->lifeparams->gen == 0)
|
---|
[421] | 214 | {
|
---|
[476] | 215 | properEnergy = ( cr.energy >= cr.data->genes->min_repro_energies[cr.data->lifeparams->gen] );
|
---|
[422] | 216 | }
|
---|
| 217 | else
|
---|
| 218 | {
|
---|
[476] | 219 | properEnergy = ( cr.energy >= cr.data->genes[0]->min_repro_energies[cr.data->lifeparams->gen] ); //TODO gene selection
|
---|
[422] | 220 | }
|
---|
| 221 |
|
---|
| 222 | //if creature has proper energy
|
---|
| 223 | if ( properEnergy && cr.signals.size == 0)
|
---|
| 224 | {
|
---|
| 225 | //reproduce with probability repro_prob
|
---|
| 226 | if (Math.rnd01 <= ExpParams.repro_prob) //TODO env trigger
|
---|
[421] | 227 | {
|
---|
[422] | 228 | reproduced = readyToRepro(cr);
|
---|
[421] | 229 | }
|
---|
[476] | 230 | else if (cr.signals.receive("repro"+cr.data->lifeparams->species) > 0)
|
---|
[421] | 231 | {
|
---|
[422] | 232 | reproduced = readyToRepro(cr);
|
---|
[421] | 233 | }
|
---|
[422] | 234 | if (reproduced == 1)
|
---|
[430] | 235 | return 1;
|
---|
[421] | 236 | }
|
---|
| 237 |
|
---|
[422] | 238 | else if (!properEnergy)
|
---|
[421] | 239 | {
|
---|
[422] | 240 | cr.signals.clear();
|
---|
[476] | 241 | cr.data->lifeparams->reproduce = 0;
|
---|
[421] | 242 | }
|
---|
[430] | 243 |
|
---|
| 244 | return 0;
|
---|
[422] | 245 | }
|
---|
[421] | 246 |
|
---|
[422] | 247 | function crossover(parent, gene)
|
---|
| 248 | {
|
---|
[476] | 249 | var tmp = parent.data->genes[0][gene];
|
---|
| 250 | parent.data->genes[0][gene] = parent.data->genes[1][gene];
|
---|
| 251 | parent.data->genes[1][gene] = tmp;
|
---|
[422] | 252 | }
|
---|
[421] | 253 |
|
---|
[476] | 254 | function createOffspring(geno, energy, parent_genes, parent_lifeparams)
|
---|
[422] | 255 | {
|
---|
| 256 | var cr = Populations[0].add(geno);
|
---|
| 257 | cr.energy0 = energy;
|
---|
| 258 | cr.energy = cr.energy0;
|
---|
[476] | 259 | setGenotype({"cr" : cr, "parent_genes" : parent_genes, "parent_lifeparams" : parent_lifeparams, "opt" : 1});
|
---|
[422] | 260 | placeRandomlyNotColliding(cr);
|
---|
[421] | 261 | }
|
---|