removed mut prob balancing
This commit is contained in:
@@ -192,15 +192,12 @@ class ControlPanel {
|
||||
switch(this.id){
|
||||
case "add-prob":
|
||||
Hyperparams.addProb = this.value;
|
||||
Hyperparams.balanceMutationProbs(1);
|
||||
break;
|
||||
case "change-prob":
|
||||
Hyperparams.changeProb = this.value;
|
||||
Hyperparams.balanceMutationProbs(2);
|
||||
break;
|
||||
case "remove-prob":
|
||||
Hyperparams.removeProb = this.value;
|
||||
Hyperparams.balanceMutationProbs(3);
|
||||
break;
|
||||
}
|
||||
$('#add-prob').val(Math.floor(Hyperparams.addProb));
|
||||
|
||||
@@ -29,24 +29,6 @@ const Hyperparams = {
|
||||
|
||||
this.foodDropProb = 0;
|
||||
},
|
||||
|
||||
balanceMutationProbs : function(choice) {
|
||||
if (choice == 1) {
|
||||
var remaining = 100 - this.addProb;
|
||||
this.changeProb = remaining/2;
|
||||
this.removeProb = remaining/2;
|
||||
}
|
||||
else if (choice == 2) {
|
||||
var remaining = 100 - this.changeProb;
|
||||
this.addProb = remaining/2;
|
||||
this.removeProb = remaining/2;
|
||||
}
|
||||
else {
|
||||
var remaining = 100 - this.removeProb;
|
||||
this.changeProb = remaining/2;
|
||||
this.addProb = remaining/2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Hyperparams.setDefaults();
|
||||
|
||||
@@ -123,42 +123,37 @@ class Organism {
|
||||
}
|
||||
|
||||
mutate() {
|
||||
var choice = Math.floor(Math.random() * 100);
|
||||
var mutated = false;
|
||||
if (choice <= Hyperparams.addProb) {
|
||||
// add cell
|
||||
// console.log("add cell")
|
||||
|
||||
var branch = this.anatomy.getRandomCell();
|
||||
var state = CellStates.getRandomLivingType();//branch.state;
|
||||
var growth_direction = Neighbors.all[Math.floor(Math.random() * Neighbors.all.length)]
|
||||
var c = branch.loc_col+growth_direction[0];
|
||||
var r = branch.loc_row+growth_direction[1];
|
||||
let mutated = false;
|
||||
if (this.calcRandomChance(Hyperparams.addProb)) {
|
||||
let branch = this.anatomy.getRandomCell();
|
||||
let state = CellStates.getRandomLivingType();//branch.state;
|
||||
let growth_direction = Neighbors.all[Math.floor(Math.random() * Neighbors.all.length)]
|
||||
let c = branch.loc_col+growth_direction[0];
|
||||
let r = branch.loc_row+growth_direction[1];
|
||||
if (this.anatomy.canAddCellAt(c, r)){
|
||||
mutated = true;
|
||||
this.anatomy.addRandomizedCell(state, c, r);
|
||||
}
|
||||
}
|
||||
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb){
|
||||
// change cell
|
||||
var cell = this.anatomy.getRandomCell();
|
||||
var state = CellStates.getRandomLivingType();
|
||||
// console.log("change cell", state)
|
||||
if (this.calcRandomChance(Hyperparams.changeProb)){
|
||||
let cell = this.anatomy.getRandomCell();
|
||||
let state = CellStates.getRandomLivingType();
|
||||
this.anatomy.replaceCell(state, cell.loc_col, cell.loc_row);
|
||||
mutated = true;
|
||||
}
|
||||
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb + Hyperparams.removeProb){
|
||||
// remove cell
|
||||
// console.log("remove cell")
|
||||
|
||||
if (this.calcRandomChance(Hyperparams.removeProb)){
|
||||
if(this.anatomy.cells.length > 1) {
|
||||
var cell = this.anatomy.getRandomCell();
|
||||
let cell = this.anatomy.getRandomCell();
|
||||
mutated = this.anatomy.removeCell(cell.loc_col, cell.loc_row);
|
||||
}
|
||||
}
|
||||
return mutated;
|
||||
}
|
||||
|
||||
calcRandomChance(prob) {
|
||||
return (Math.random() * 100) <= prob;
|
||||
}
|
||||
|
||||
attemptMove() {
|
||||
var direction = Directions.scalars[this.direction];
|
||||
var direction_c = direction[0];
|
||||
|
||||
Reference in New Issue
Block a user