Added evolved birth distance

This commit is contained in:
MaxRobinsonTheGreat
2020-08-03 18:22:45 -06:00
parent add3872423
commit 310fc39216
6 changed files with 331 additions and 8 deletions

View File

@@ -190,6 +190,7 @@ class ControlPanel {
$('.edit-mode-btn').click( function() {
var prev_mode = self.env_controller.mode;
$('#cell-selections').css('display', 'none');
$('#organism-options').css('display', 'none');
switch(this.id){
case "food-drop":
self.setMode(Modes.FoodDrop);
@@ -206,6 +207,7 @@ class ControlPanel {
case "edit":
self.setMode(Modes.Edit);
$('#cell-selections').css('display', 'block');
$('#organism-options').css('display', 'block');
break;
case "drop-org":
self.setMode(Modes.Clone);

View File

@@ -9,6 +9,7 @@ class EditorController extends CanvasController{
this.edit_cell_type = null;
this.highlight_org = false;
this.defineCellTypeSelection();
this.defineEditorOptions();
}
mouseMove() {
@@ -56,6 +57,13 @@ class EditorController extends CanvasController{
$(selected).css("border-color", "yellow");
});
}
defineEditorOptions() {
$('#birth-distance').change ( function() {
this.env.organism.birth_distance = $('#birth-distance').val();
}.bind(this));
}
}
module.exports = EditorController;

View File

@@ -26,6 +26,7 @@ class Organism {
this.move_range = 4;
this.mutability = 5;
this.damage = 0;
this.birth_distance = 4;
if (parent != null) {
this.inherit(parent);
}
@@ -86,6 +87,7 @@ class Organism {
inherit(parent) {
this.move_range = parent.move_range;
this.mutability = parent.mutability;
this.birth_distance = parent.birth_distance;
for (var c of parent.cells){
//deep copy parent cells
this.addCell(c.type, c.loc_col, c.loc_row);
@@ -130,12 +132,13 @@ class Organism {
if (Math.random() * 100 <= prob) {
org.mutate();
}
var direction = Directions.getRandomScalar();
var direction_c = direction[0];
var direction_r = direction[1];
var offset = (Math.floor(Math.random() * 3));
var basemovement = Math.min(2+this.cells.length, 25);
var basemovement = this.birth_distance;//Math.min(2+this.cells.length, 25);
var new_c = this.c + (direction_c*basemovement) + (direction_c*offset);
var new_r = this.r + (direction_r*basemovement) + (direction_r*offset);
@@ -161,6 +164,7 @@ class Organism {
var c = branch.loc_col+growth_direction[0];
var r = branch.loc_row+growth_direction[1];
mutated = this.addCell(type, c, r);
this.birth_distance++;
}
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb){
// change cell
@@ -177,11 +181,14 @@ class Organism {
}
}
if (this.is_mover) {
if (this.is_mover && Math.random() * 100 <= 10) {
this.move_range += Math.floor(Math.random() * 4) - 2;
if (this.move_range <= 0){
this.move_range = 1;
}
};
}
if (Math.random() * 100 <= 10) {
this.birth_distance += Math.floor(Math.random() * 4) - 2;
}
return mutated;
}