Index: /experiments/frams/foraminifera/data/scripts/forams_benthic.expdef
===================================================================
--- /experiments/frams/foraminifera/data/scripts/forams_benthic.expdef	(revision 403)
+++ /experiments/frams/foraminifera/data/scripts/forams_benthic.expdef	(revision 404)
@@ -34,5 +34,4 @@
 global foodenergywaiting;
 global reprocounter;
-global delta_change;
 
 @include "forams_repro.inc"
@@ -53,5 +52,5 @@
 	pop.name = "Creatures";
 	pop.en_assim = 0;
-	pop.nnsim = 1;
+	pop.nnsim = 0;
 	pop.enableperf = 1;
 	pop.death = 1;
@@ -70,9 +69,10 @@
 	pop.othermask = 0x10000;
 
-
-	var size_h = ExpParams.haplo_rad * ExpParams.delta_rate + ExpParams.haplo_rad;
-	var size_d = ExpParams.diplo_rad * ExpParams.delta_rate + ExpParams.diplo_rad;
-	ExpParams.gend = "//0\np:sh=1,sx=" + ExpParams.diplo_rad + ",sy=" + ExpParams.diplo_rad + ",sz=" + ExpParams.diplo_rad + ", rz=3.14159265358979";
-	ExpParams.genh = "//0\np:sh=1,sx=" + size_h + ",sy=" + size_h + ",sz=" + size_h + ", rz=3.14159265358979";
+	//radius of the chamber
+        ExpParams.rads = [1.2, 0.6];
+	//inital genotypes 
+	ExpParams.genh = "//0\np:sh=1,sx=" + ExpParams.rads[0] + ",sy=" + ExpParams.rads[0] + ",sz=" + ExpParams.rads[0] + ", rz=3.14159265358979"; 
+	ExpParams.gend = "//0\np:sh=1,sx=" + ExpParams.rads[1] + ",sy=" + ExpParams.rads[1] + ",sz=" + ExpParams.rads[1] + ", rz=3.14159265358979";
+        ExpParams.gend += "\nn:p=0,d=\"S\"";
 	ExpParams.e_meta = 0.1;
 	ExpParams.feedrate = 0.5;
@@ -91,7 +91,4 @@
 	ExpParams.v_min_d = 300;
 	ExpParams.v_min_h = 300;
-	//radius of the chamber
-	ExpParams.haplo_rad = 1.2;
-	ExpParams.diplo_rad = 0.6;
 	//minimal age for reproduction
 	ExpParams.age_min_d = 100;
@@ -104,6 +101,4 @@
 	ExpParams.repro_thr = 1;
 
-	//size change rate
-	ExpParams.delta_rate = 0.1;
 	//grwoth speed in time steps
 	ExpParams.growth_step = 50;
@@ -118,6 +113,4 @@
 	World.wrldsiz = ExpParams.wsize;
 	World.wrldbnd = 1;
-
-	delta_change = 0.5;
 }
 
@@ -136,6 +129,6 @@
 		cr.energ0 = ExpParams.v_min_h - ExpParams.repro_thr;
 		cr.energy = cr.energ0;
-		cr.user1 = {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h, "delta_h" : ExpParams.haplo_rad * ExpParams.delta_rate, "delta_d" : ExpParams.diplo_rad * ExpParams.delta_rate};
-		cr.user2 = {"Va" : ExpParams.v_min_h - ExpParams.repro_thr, "gen" : 0, "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.haplo_rad, "vinit" : ExpParams.v_min_h - ExpParams.repro_thr};
+		cr.user1 = {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h};
+		cr.user2 = {"Va" : ExpParams.v_min_h - ExpParams.repro_thr, "gen" : 0, "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit" : ExpParams.v_min_h - ExpParams.repro_thr};
 	}
 	ExpState.totaltestedcr = 0;
@@ -230,10 +223,10 @@
 	cr.signals.add("repro");
 	cr.signals[0].power = 1;
-
 }
 
 function onCreaturesStep(cr)
 {
-	cr.moveAbs(cr.pos_x, cr.pos_y, 0); //adjustment in z axis
+        //TODO moving inside sediment?
+	cr.moveAbs(cr.pos_x, cr.pos_y, 0); //adjustment in z axis 
 	var p = cr.getMechPart(0);
 	var n = cr.signals.receiveSet("food", ExpParams.food_range);
@@ -276,4 +269,5 @@
 	if (cr.energy > 100)
 	{
+                //TODO energy costs dependant on size
 		// cr.energy_m = cr.user2["Va"]/cr.user2["vinit"];
 	}
@@ -281,35 +275,23 @@
 	if (cr.lifespan >= ExpParams.max_age)
 	{
+		//TODO what is max age value? should there be one?
 		Populations[0].kill(cr);
+                return;
 	}
 
 	//foram growth
-	else if (cr.lifespan == cr.user2["growth_step"])
-	{
-		var pos = [cr.center_x, cr.center_y, cr.center_z];
-		var energy = cr.energy;
-		var cr2 = null;
-		if (cr.user2["gen"] == 0)
-		{
-			var new_r = ExpParams.haplo_rad * Math.min(Math.max(cr.user2["Va"] / cr.user2["vinit"] * 0.5, 1), 2.5);
-			cr.user2["rsize"] = new_r;
-			cr2 = Populations[0].add("//0\np:sh=1,sx=" + cr.user2["rsize"] + ",sy=" + cr.user2["rsize"] + ",sz=" + cr.user2["rsize"] + ", rz=3.14159265358979");
-			cr2.user1 = {"vamin" : cr.user1["vamin"], "amin": cr.user1["amin"], "delta_h" : cr.user1["delta_h"], "delta_d" : cr.user1["delta_d"]};
-		}
-		else if (cr.user2["gen"] == 1)
-		{
-			var new_r = ExpParams.diplo_rad * Math.min(Math.max(cr.user2["Va"] / cr.user2["vinit"] * 0.5, 1), 2.5);
-			cr.user2["rsize"] = new_r;
-
-			var geno = "//0\np:sh=1,sx=" + cr.user2["rsize"] + ",sy=" + cr.user2["rsize"] + ",sz=" + cr.user2["rsize"] + ", rz=3.14159265358979";
-			geno += "\nn:p=0,d=\"S\""; //TODO is this the only difference with haploid code? TODO why initial genotypes are not used as defined in ExpParams?
+	if (cr.lifespan == cr.user2["growth_step"])
+	{
+                //TODO how size is related to the energy?
+                cr.user2["rsize"] = ExpParams.rads[cr.user2["gen"]] * Math.min(Math.max(float(cr.user2["Va"] / cr.user2["vinit"]) * 0.5, 1.0), 2.5);
+		var geno = "//0\np:sh=1,sx=" + cr.user2["rsize"] + ",sy=" + cr.user2["rsize"] + ",sz=" + cr.user2["rsize"] + ", rz=3.14159265358979";
+		if (cr.user2["gen"] == 1)
+		{
+			geno += "\nn:p=0,d=\"S\""; //TODO why initial genotypes are not used as defined in ExpParams?
 			//TODO maybe it would be nice if they rotated so the "S" would show where they are going (direction/intention)
-			cr2 = Populations[0].add(geno);
-
-
-			cr2.user1 = [ {"vamin" : cr.user1[0]["vamin"], "amin": cr.user1[0]["amin"], "delta_h" : cr.user1[0].get("delta_h"), "delta_d" : cr.user1[0]["delta_d"]  }, {"vamin" : cr.user1[1]["vamin"], "amin": cr.user1[1]["amin"], "delta_h" : cr.user1[1]["delta_h"], "delta_d" : cr.user1[1]["delta_d"]  }];
-		}
-		cr2.energy = energy;
-		cr2.user2 = {"Va" : cr.user2["Va"], "gen" : cr.user2["gen"], "growth_step" : cr.user2["growth_step"], "rsize" : cr.user2["rsize"], "vinit": cr.user2["vinit"]};
+		}
+                var cr2 = Populations[0].add(geno);
+		cr2.energy = cr.energy;
+		setGenotype(cr2, cr.user1, cr.user2);
 		cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
 
@@ -355,4 +337,18 @@
 }
 
+function setGenotype(cr, new_user1, new_user2)
+{
+	cr.user2 = {"Va" : new_user2["Va"], "gen" : new_user2["gen"], "growth_step" : new_user2["growth_step"], "rsize" : new_user2["rsize"], "vinit": new_user2["vinit"]};
+	if (cr.user2["gen"] == 0)
+	{
+		cr.user1 = {"vamin" : new_user1["vamin"], "amin": new_user1["amin"] };
+	}
+	else if (cr.user2["gen"] == 1)
+	{
+		cr.user1 = [ {"vamin" : new_user1[0]["vamin"], "amin": new_user1[0]["amin"] }, {"vamin" : new_user1[1]["vamin"], "amin": new_user1[1]["amin"] }];
+	}       
+
+}
+
 // -------------------------------- creature end --------------------------------
 
@@ -376,13 +372,5 @@
 	cr.signals[0].value = cr.getMechPart(0);
 
-	var retry = 100; //try 100 times
-	while (retry--)
-	{
-		placeCreatureRandomly(cr, 0, 0);
-		if (!cr.boundingBoxCollisions(0))
-			return cr;
-	}
-
-	return cr;
+	placeRandomlyNotColliding(cr);
 }
 
@@ -395,7 +383,5 @@
 		Collision.Creature1.energy_m = Collision.Creature1.energy_m + e;
 		Collision.Creature2.energy_p = Collision.Creature2.energy_p + e;
-		var ener = float(Collision.Creature2.user2["Va"]);
-		var sum = float(float(ener) + float(e));
-		Collision.Creature2.user2["Va"] = float(sum);
+		Collision.Creature2.user2["Va"] = float(Collision.Creature2.user2["Va"]) + float(e);
 	}
 }
@@ -434,32 +420,12 @@
 
 prop:
-id:haplo_rad
-name:Haploid radius
-type:f 0.1 3 1.2
-
-prop:
 id:growth_step
 name:Growth step
-type:d 50 10000 1000
-
-prop:
-id:delta_rate
-name:Delta rate
-type:f 0.0001 0.1 0.001
-
-prop:
-id:diplo_rad
-name:Diploid radius
-type:f 0.1 3 0.6
-
-prop:
-id:foodPop
-name:Food size
-type:d 1 1000 10
-
-prop:
-id:age_min
-name:Minimal age for reproduction
-type:d 100 10000 200
+type:d 10 10000 1000
+
+prop:
+id:rads
+name: haploid and diploid radius
+type:x
 
 prop:
@@ -489,5 +455,5 @@
 prop:
 id:repro_thr
-name:Threshold for reproduction
+name:amount of energy initial creatures need to gather to reproduce
 type:d 1 1000 1
 
@@ -615,4 +581,9 @@
 flags:16
 
+prop:
+id:foodPop
+name:food size
+type:d 1 1000 10
+
 state:
 id:food
Index: /experiments/frams/foraminifera/data/scripts/forams_repro.inc
===================================================================
--- /experiments/frams/foraminifera/data/scripts/forams_repro.inc	(revision 403)
+++ /experiments/frams/foraminifera/data/scripts/forams_repro.inc	(revision 404)
@@ -4,5 +4,5 @@
 // -------------------------------- step begin --------------------------------
 
-function reproduce_haploid(repro_list, number)
+function reproduce_haploid(repro_list)
 {
 	var len = repro_list.size;
@@ -14,49 +14,15 @@
 		var parent2 = Populations[0].get(repro_list[i + 1]);
 
-		number = parent.user2["Va"] / ExpParams.ofnumd + parent2.user2["Va"] / ExpParams.ofnumd;
+		var number = parent.user2["Va"] / ExpParams.ofnumd + parent2.user2["Va"] / ExpParams.ofnumd;
+
 		for (var j = 0; j < number; j++)
 		{
-			//size
-			var rsize = (parent.user1["delta_d"] + ExpParams.diplo_rad);
-			if (Math.rnd01 < 0.5)
-			{
-				rsize = parent2.user1["delta_d"] + ExpParams.diplo_rad;
-			}
-
-			var deltas = parent.user1["delta_d"];
-			//mutation
-			if (Math.rnd01 < ExpParams.mutationprob)
-			{
-				var diff = delta_change * deltas;
-				if (Math.rnd01 < 0.5)
-				{
-					deltas -= diff;
-				}
-				else
-				{
-					deltas += diff;
-				}
-				rsize = ExpParams.diplo_rad + deltas;
-			}
-
-			var geno = "//0\np:sh=1,sx=" + rsize + ",sy=" + rsize + ",sz=" + rsize + ", rz=3.14159265358979";
-			geno += "\nn:p=0,d=\"S\""; //TODO is this the only difference with haploid code? TODO why initial genotypes are not used as defined in ExpParams?
-			var cr = Populations[0].add(geno);
-			cr.energ0 = ExpParams.ofnumd;
-			cr.energy = cr.energ0;
-			var dsize =  ExpParams.diplo_rad * ExpParams.delta_rate + ExpParams.diplo_rad;
-			cr.user1 = [ {"vamin" : (rsize / dsize) * ExpParams.v_min_d, "amin": parent.user1["amin"], "delta_h" : parent.user1["delta_h"], "delta_d" : deltas }, {"vamin" : (rsize / dsize) * ExpParams.v_min_d, "amin": parent2.user1["amin"], "delta_h" : parent2.user1["delta_h"], "delta_d" : deltas }];
-			cr.user2 = { "Va" : cr.energ0, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": rsize, "vinit": cr.energ0};
-			placeRandomlyNotColliding(cr);
-		}
-	}
-
-	for (var j = 0; j < repro_list.size; j++)
-	{
-		Populations[0].kill(repro_list[j]);
-	}
-}
-
-function reproduce_diploid(repro_list, number)
+			createOffspring(ExpParams.gend, ExpParams.ofnumd, [parent.user1, parent2.user1], {"Va" : ExpParams.ofnumd, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": ExpParams.rads[1], "vinit": ExpParams.ofnumd}); //TODO genes from both generations in user1
+		}
+	}
+	killParents(repro_list);
+}
+
+function reproduce_diploid(repro_list)
 {
 	for (var i = 0; i < repro_list.size; i++)
@@ -64,10 +30,12 @@
 		var parent = Populations[0].get(repro_list[i]);
 
+		if (parent.user2["gen"] != 1)
+		{
+			Simulator.print("gen: " + parent.user2["gen"]);
+		}
+
 		if (parent.user2["gen"] == 1)
 		{
-
 			var number = parent.user2["Va"] / ExpParams.ofnumh;
-
-
 			for (var j = 0; j < number / 2; j++)
 			{
@@ -76,7 +44,5 @@
 				if (Math.rnd01 < ExpParams.crossprob)
 				{
-					var tmp = parent.user1[0]["vamin"];
-					parent.user1[0]["vamin"] = parent.user1[1]["vamin"];
-					parent.user1[1]["vamin"] = tmp;
+					crossover(parent, "vamin");
 					crossed = 1;
 				}
@@ -84,32 +50,5 @@
 				for (var k = 0; k < 2; k++)
 				{
-					var rsize = parent.user1[k]["delta_h"]  + ExpParams.haplo_rad;
-					var vamin = parent.user1[k]["vamin"];
-					var deltas =  parent.user1[k]["delta_h"];
-
-
-					if (Math.rnd01 < ExpParams.mutationprob)
-					{
-						var diff = delta_change * deltas;
-						if (Math.rnd01 < 0.5)
-						{
-							deltas -= diff;
-						}
-						else
-						{
-							deltas += diff;
-						}
-						rsize = ExpParams.diplo_rad + deltas;
-					}
-
-					var geno = "//0\np:sh=1,sx=" + rsize + ",sy=" + rsize + ",sz=" + rsize + ", rz=3.14159265358979";
-					var cr = Populations[0].add(geno);
-					cr.energ0 = ExpParams.ofnumh;
-					cr.energy = cr.energ0;
-					//vamin depends on rsize
-					var hsize = ExpParams.haplo_rad * ExpParams.delta_rate + ExpParams.haplo_rad;
-					cr.user1 = {"vamin" : (rsize / hsize) * ExpParams.v_min_h, "amin": ExpParams.age_min_d, "delta_h" : deltas, "delta_d" : parent.user1[0]["delta_d"]};
-					cr.user2 = { "Va" : cr.energ0, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : rsize, "vinit": cr.energ0};
-					placeRandomlyNotColliding(cr);
+					createOffspring(ExpParams.genh, ExpParams.ofnumh, {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h}, {"Va" : ExpParams.ofnumh, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit": ExpParams.ofnumh});
 				}
 
@@ -117,13 +56,22 @@
 				if (crossed == 1)
 				{
-					var tmp = parent.user1[0]["vamin"];
-					parent.user1[0]["vamin"] = parent.user1[1]["vamin"];
-					parent.user1[1]["vamin"] = tmp;
+					crossover(parent, "vamin");
 					crossed = 0;
 				}
-
 			}
 		}
 	}
+	killParents(repro_list);
+}
+
+function crossover(parent, gene)
+{
+	var tmp = parent.user1[0][gene];
+	parent.user1[0][gene] = parent.user1[1][gene];
+	parent.user1[1][gene] = tmp;
+}
+
+function killParents(repro_list)
+{
 	for (var j = 0; j < repro_list.size; j++)
 	{
@@ -132,4 +80,12 @@
 }
 
+function createOffspring(geno, energy, new_user1, new_user2)
+{
+	var cr = Populations[0].add(geno);
+	cr.energ0 = energy;
+	cr.energy = cr.energ0;
+	setGenotype(cr, new_user1, new_user2);
+	placeRandomlyNotColliding(cr);
+}
 
 function onStep()
@@ -152,5 +108,5 @@
 			haploids += 1;
 			e_inc_h += cr.energy;
-			size_h += cr.user1["delta_h"] + ExpParams.haplo_rad;
+			size_h += ExpParams.rads[0]; //TODO change of size dependant on gene
 			vmin_h += cr.user1["vamin"];
 		}
@@ -159,5 +115,5 @@
 			diploids += 1;
 			e_inc_d += cr.energy;
-			size_d += cr.user1[0]["delta_d"] + ExpParams.diplo_rad;
+			size_d += ExpParams.rads[1]; //TODO change of size dependant on gene
 			vmin_d += cr.user1[0]["vamin"];
 		}
@@ -219,5 +175,5 @@
 					to_repro_h.add(i);
 				}
-				else if (cr.user2["gen"] == 1)
+				if (cr.user2["gen"] == 1)
 				{
 					to_repro_d.add(i);
@@ -227,9 +183,9 @@
 		if (to_repro_h.size > 1)
 		{
-			reproduce_haploid(to_repro_h, ExpParams.ofnumh);
+			reproduce_haploid(to_repro_h);
 		}
 		if (to_repro_d.size > 0)
 		{
-			reproduce_diploid(to_repro_d, ExpParams.ofnumd);
+			reproduce_diploid(to_repro_d);
 		}
 	}
