Merge pull request #43 from MaxRobinsonTheGreat/mut-probs-ui

removed mut prob balancing
This commit is contained in:
Max Robinson
2021-11-28 14:36:09 -06:00
committed by GitHub
3 changed files with 16 additions and 42 deletions

View File

@@ -192,15 +192,12 @@ class ControlPanel {
switch(this.id){ switch(this.id){
case "add-prob": case "add-prob":
Hyperparams.addProb = this.value; Hyperparams.addProb = this.value;
Hyperparams.balanceMutationProbs(1);
break; break;
case "change-prob": case "change-prob":
Hyperparams.changeProb = this.value; Hyperparams.changeProb = this.value;
Hyperparams.balanceMutationProbs(2);
break; break;
case "remove-prob": case "remove-prob":
Hyperparams.removeProb = this.value; Hyperparams.removeProb = this.value;
Hyperparams.balanceMutationProbs(3);
break; break;
} }
$('#add-prob').val(Math.floor(Hyperparams.addProb)); $('#add-prob').val(Math.floor(Hyperparams.addProb));

View File

@@ -29,24 +29,6 @@ const Hyperparams = {
this.foodDropProb = 0; 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(); Hyperparams.setDefaults();

View File

@@ -123,42 +123,37 @@ class Organism {
} }
mutate() { mutate() {
var choice = Math.floor(Math.random() * 100); let mutated = false;
var mutated = false; if (this.calcRandomChance(Hyperparams.addProb)) {
if (choice <= Hyperparams.addProb) { let branch = this.anatomy.getRandomCell();
// add cell let state = CellStates.getRandomLivingType();//branch.state;
// console.log("add cell") let growth_direction = Neighbors.all[Math.floor(Math.random() * Neighbors.all.length)]
let c = branch.loc_col+growth_direction[0];
var branch = this.anatomy.getRandomCell(); let r = branch.loc_row+growth_direction[1];
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];
if (this.anatomy.canAddCellAt(c, r)){ if (this.anatomy.canAddCellAt(c, r)){
mutated = true; mutated = true;
this.anatomy.addRandomizedCell(state, c, r); this.anatomy.addRandomizedCell(state, c, r);
} }
} }
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb){ if (this.calcRandomChance(Hyperparams.changeProb)){
// change cell let cell = this.anatomy.getRandomCell();
var cell = this.anatomy.getRandomCell(); let state = CellStates.getRandomLivingType();
var state = CellStates.getRandomLivingType();
// console.log("change cell", state)
this.anatomy.replaceCell(state, cell.loc_col, cell.loc_row); this.anatomy.replaceCell(state, cell.loc_col, cell.loc_row);
mutated = true; mutated = true;
} }
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb + Hyperparams.removeProb){ if (this.calcRandomChance(Hyperparams.removeProb)){
// remove cell
// console.log("remove cell")
if(this.anatomy.cells.length > 1) { 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); mutated = this.anatomy.removeCell(cell.loc_col, cell.loc_row);
} }
} }
return mutated; return mutated;
} }
calcRandomChance(prob) {
return (Math.random() * 100) <= prob;
}
attemptMove() { attemptMove() {
var direction = Directions.scalars[this.direction]; var direction = Directions.scalars[this.direction];
var direction_c = direction[0]; var direction_c = direction[0];