fixed species tracking bug
This commit is contained in:
@@ -61,7 +61,7 @@ class Anatomy {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.checkTypeChange(cell.state);
|
||||
this.checkTypeChange();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -93,9 +93,7 @@ class Anatomy {
|
||||
}
|
||||
|
||||
getNeighborsOfCell(col, row) {
|
||||
|
||||
var neighbors = [];
|
||||
|
||||
for (var x = -1; x <= 1; x++) {
|
||||
for (var y = -1; y <= 1; y++) {
|
||||
|
||||
@@ -107,6 +105,19 @@ class Anatomy {
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
isEqual(anatomy) { // currently unused helper func. inefficient, avoid usage in prod.
|
||||
if (this.cells.length !== anatomy.cells.length) return false;
|
||||
for (let i in this.cells) {
|
||||
let my_cell = this.cells[i];
|
||||
let their_cell = anatomy.cells[i];
|
||||
if (my_cell.loc_col !== their_cell.loc_col ||
|
||||
my_cell.loc_row !== their_cell.loc_row ||
|
||||
my_cell.state !== their_cell.state)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Anatomy;
|
||||
@@ -118,19 +118,21 @@ class Organism {
|
||||
}
|
||||
}
|
||||
Math.max(this.food_collected -= this.foodNeeded(), 0);
|
||||
|
||||
}
|
||||
|
||||
mutate() {
|
||||
let mutated = false;
|
||||
let added = false;
|
||||
let changed = false;
|
||||
let removed = false;
|
||||
if (this.calcRandomChance(Hyperparams.addProb)) {
|
||||
// console.log('add')
|
||||
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;
|
||||
added = true;
|
||||
this.anatomy.addRandomizedCell(state, c, r);
|
||||
}
|
||||
}
|
||||
@@ -138,15 +140,15 @@ class Organism {
|
||||
let cell = this.anatomy.getRandomCell();
|
||||
let state = CellStates.getRandomLivingType();
|
||||
this.anatomy.replaceCell(state, cell.loc_col, cell.loc_row);
|
||||
mutated = true;
|
||||
changed = true;
|
||||
}
|
||||
if (this.calcRandomChance(Hyperparams.removeProb)){
|
||||
if(this.anatomy.cells.length > 1) {
|
||||
let cell = this.anatomy.getRandomCell();
|
||||
mutated = this.anatomy.removeCell(cell.loc_col, cell.loc_row);
|
||||
removed = this.anatomy.removeCell(cell.loc_col, cell.loc_row);
|
||||
}
|
||||
}
|
||||
return mutated;
|
||||
return added || changed || removed;
|
||||
}
|
||||
|
||||
calcRandomChance(prob) {
|
||||
|
||||
Reference in New Issue
Block a user