Merge branch 'develop' into random-orgs
This commit is contained in:
@@ -5,7 +5,7 @@ const Hyperparams = require("../../Hyperparameters");
|
||||
class Cell{
|
||||
constructor(state, col, row, x, y){
|
||||
this.owner = null; // owner organism
|
||||
this.cell_owner = null; // owner cell of ^that organism
|
||||
this.cell_owner = null; // specific body cell of the owner organism that occupies this grid cell
|
||||
this.setType(state);
|
||||
this.col = col;
|
||||
this.row = row;
|
||||
|
||||
@@ -17,7 +17,7 @@ class Organism {
|
||||
this.anatomy = new Anatomy(this)
|
||||
this.direction = Directions.down; // direction of movement
|
||||
this.rotation = Directions.up; // direction of rotation
|
||||
this.can_rotate = Hyperparams.moversCanRotate;
|
||||
this.can_rotate = Hyperparams.rotationEnabled;
|
||||
this.move_count = 0;
|
||||
this.move_range = 4;
|
||||
this.ignore_brain_for = 0;
|
||||
@@ -47,11 +47,10 @@ class Organism {
|
||||
|
||||
// amount of food required before it can reproduce
|
||||
foodNeeded() {
|
||||
return this.anatomy.cells.length;
|
||||
return this.anatomy.is_mover ? this.anatomy.cells.length + Hyperparams.extraMoverFoodCost : this.anatomy.cells.length;
|
||||
}
|
||||
|
||||
lifespan() {
|
||||
// console.log(Hyperparams.lifespanMultiplier)
|
||||
return this.anatomy.cells.length * Hyperparams.lifespanMultiplier;
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ class Organism {
|
||||
//produce mutated child
|
||||
//check nearby locations (is there room and a direct path)
|
||||
var org = new Organism(0, 0, this.env, this);
|
||||
if(Hyperparams.offspringRotate){
|
||||
if(Hyperparams.rotationEnabled){
|
||||
org.rotation = Directions.getRandomDirection();
|
||||
}
|
||||
var prob = this.mutability;
|
||||
@@ -118,47 +117,42 @@ class Organism {
|
||||
org.species.addPop();
|
||||
}
|
||||
}
|
||||
this.food_collected -= this.foodNeeded();
|
||||
Math.max(this.food_collected -= this.foodNeeded(), 0);
|
||||
|
||||
}
|
||||
|
||||
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];
|
||||
@@ -248,8 +242,7 @@ class Organism {
|
||||
if (cell==null) {
|
||||
return false;
|
||||
}
|
||||
// console.log(cell.owner == this)
|
||||
if (cell.owner==this || cell.state==CellStates.empty || (!Hyperparams.foodBlocksReproduction && cell.state==CellStates.food) || (ignore_armor && loccell.state==CellStates.armor && cell.state==CellStates.food)){
|
||||
if (cell.owner==this || cell.state==CellStates.empty || (!Hyperparams.foodBlocksReproduction && cell.state==CellStates.food)){
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user