Added body cell functionality

This commit is contained in:
MaxRobinsonTheGreat
2020-08-17 23:35:47 -06:00
parent 3589df3919
commit 3f05fbe7f9
24 changed files with 598 additions and 294 deletions

View File

@@ -0,0 +1,31 @@
const CellStates = require("../CellStates");
const BodyCell = require("./BodyCell");
const Hyperparams = require("../../../Hyperparameters");
class ProducerCell extends BodyCell{
constructor(org, loc_col, loc_row){
super(CellStates.producer, org, loc_col, loc_row);
this.org.is_producer = true;
}
performFunction() {
if (this.org.is_mover && !Hyperparams.moversCanProduce)
return;
var env = this.org.env;
var prob = Hyperparams.foodProdProb;
var real_c = this.getRealCol();
var real_r = this.getRealRow();
if (Math.random() * 100 <= prob) {
var loc = Hyperparams.growableNeighbors[Math.floor(Math.random() * Hyperparams.growableNeighbors.length)]
var loc_c=loc[0];
var loc_r=loc[1];
var cell = env.grid_map.cellAt(real_c+loc_c, real_r+loc_r);
if (cell != null && cell.state == CellStates.empty){
env.changeCell(real_c+loc_c, real_r+loc_r, CellStates.food, null);
return;
}
}
}
}
module.exports = ProducerCell;