Added body cell functionality
This commit is contained in:
@@ -8,8 +8,8 @@ class Environment{
|
||||
alert("Environment.update() must be overriden");
|
||||
}
|
||||
|
||||
changeCell(c, r, type, owner) {
|
||||
this.grid_map.setCellType(c, r, type);
|
||||
changeCell(c, r, state, owner) {
|
||||
this.grid_map.setCellType(c, r, state);
|
||||
this.grid_map.setCellOwner(c, r, owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ const Environment = require('./Environment');
|
||||
const Organism = require('../Organism/Organism');
|
||||
const GridMap = require('../Grid/GridMap');
|
||||
const Renderer = require('../Rendering/Renderer');
|
||||
const CellTypes = require('../Organism/Cell/CellTypes');
|
||||
const CellStates = require('../Organism/Cell/CellStates');
|
||||
const EditorController = require("../Controllers/EditorController");
|
||||
const Cell = require("../Organism/Cell/Cell");
|
||||
const Cell = require("../Organism/Cell/GridCell");
|
||||
const Eye = require('../Organism/Perception/Eye');
|
||||
const Directions = require('../Organism/Directions');
|
||||
|
||||
@@ -27,28 +27,27 @@ class OrganismEditor extends Environment{
|
||||
}
|
||||
}
|
||||
|
||||
changeCell(c, r, type, owner) {
|
||||
super.changeCell(c, r, type, owner);
|
||||
changeCell(c, r, state, owner) {
|
||||
super.changeCell(c, r, state, owner);
|
||||
this.renderFull();
|
||||
}
|
||||
|
||||
renderFull() {
|
||||
this.renderer.renderFullGrid(this.grid_map.grid);
|
||||
}
|
||||
|
||||
// absolute c r, not local
|
||||
addCellToOrg(c, r, type) {
|
||||
addCellToOrg(c, r, state) {
|
||||
var center = this.grid_map.getCenter();
|
||||
var loc_c = c - center[0];
|
||||
var loc_r = r - center[1];
|
||||
var prev_cell = this.organism.getLocalCell(loc_c, loc_r)
|
||||
if (prev_cell != null) {
|
||||
console.log(prev_cell.type)
|
||||
if (type == CellTypes.eye && prev_cell.type != CellTypes.eye){
|
||||
prev_cell.eye = new Eye(Directions.up);
|
||||
|
||||
}
|
||||
prev_cell.type = type;
|
||||
this.changeCell(c, r, type, this.organism);
|
||||
var new_cell = this.organism.replaceCell(state, prev_cell.loc_col, prev_cell.loc_row, false);
|
||||
this.changeCell(c, r, state, new_cell);
|
||||
}
|
||||
else if (this.organism.addCell(type, loc_c, loc_r)){
|
||||
this.changeCell(c, r, type, this.organism);
|
||||
else if (this.organism.canAddCellAt(loc_c, loc_r)){
|
||||
this.changeCell(c, r, state, this.organism.addDefaultCell(state, loc_c, loc_r));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,13 +62,13 @@ class OrganismEditor extends Environment{
|
||||
var prev_cell = this.organism.getLocalCell(loc_c, loc_r)
|
||||
if (prev_cell != null) {
|
||||
if (this.organism.removeCell(loc_c, loc_r)) {
|
||||
this.changeCell(c, r, CellTypes.empty, null);
|
||||
this.changeCell(c, r, CellStates.empty, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setOrganismToCopyOf(orig_org){
|
||||
this.grid_map.fillGrid(CellTypes.empty);
|
||||
this.grid_map.fillGrid(CellStates.empty);
|
||||
var center = this.grid_map.getCenter();
|
||||
this.organism = new Organism(center[0], center[1], this, orig_org);
|
||||
this.organism.updateGrid();
|
||||
@@ -82,10 +81,10 @@ class OrganismEditor extends Environment{
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.grid_map.fillGrid(CellTypes.empty);
|
||||
this.grid_map.fillGrid(CellStates.empty);
|
||||
var center = this.grid_map.getCenter();
|
||||
this.organism = new Organism(center[0], center[1], this, null);
|
||||
this.organism.addCell(CellTypes.mouth, 0, 0);
|
||||
this.organism.addDefaultCell(CellStates.mouth, 0, 0);
|
||||
this.organism.updateGrid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ const Grid = require('../Grid/GridMap');
|
||||
const Renderer = require('../Rendering/Renderer');
|
||||
const GridMap = require('../Grid/GridMap');
|
||||
const Organism = require('../Organism/Organism');
|
||||
const CellTypes = require('../Organism/Cell/CellTypes');
|
||||
const Cell = require('../Organism/Cell/Cell');
|
||||
const CellStates = require('../Organism/Cell/CellStates');
|
||||
const Cell = require('../Organism/Cell/GridCell');
|
||||
const EnvironmentController = require('../Controllers/EnvironmentController');
|
||||
|
||||
class WorldEnvironment extends Environment{
|
||||
@@ -54,12 +54,12 @@ class WorldEnvironment extends Environment{
|
||||
OriginOfLife() {
|
||||
var center = this.grid_map.getCenter();
|
||||
var org = new Organism(center[0], center[1], this);
|
||||
// org.addCell(CellTypes.eye, 0, 0);
|
||||
// org.addCell(CellTypes.mouth, 1, 1);
|
||||
// org.addCell(CellTypes.mover, -1, -1);
|
||||
org.addCell(CellTypes.mouth, 0, 0);
|
||||
org.addCell(CellTypes.producer, 1, 1);
|
||||
org.addCell(CellTypes.producer, -1, -1);
|
||||
org.addDefaultCell(CellStates.eye, 0, 0);
|
||||
org.addDefaultCell(CellStates.mouth, 1, 1);
|
||||
org.addDefaultCell(CellStates.mover, 1, -1);
|
||||
// org.addDefaultCell(CellStates.mouth, 0, 0);
|
||||
// org.addDefaultCell(CellStates.producer, 1, 1);
|
||||
// org.addDefaultCell(CellStates.producer, -1, -1);
|
||||
this.addOrganism(org);
|
||||
}
|
||||
|
||||
@@ -77,17 +77,17 @@ class WorldEnvironment extends Environment{
|
||||
return this.total_mutability / this.organisms.length;
|
||||
}
|
||||
|
||||
changeCell(c, r, type, owner) {
|
||||
super.changeCell(c, r, type, owner);
|
||||
changeCell(c, r, state, owner) {
|
||||
super.changeCell(c, r, state, owner);
|
||||
this.renderer.addToRender(this.grid_map.cellAt(c, r));
|
||||
if(type == CellTypes.wall)
|
||||
if(state == CellStates.wall)
|
||||
this.walls.push(this.grid_map.cellAt(c, r));
|
||||
}
|
||||
|
||||
clearWalls() {
|
||||
for(var wall of this.walls){
|
||||
if (this.grid_map.cellAt(wall.col, wall.row).type == CellTypes.wall)
|
||||
this.changeCell(wall.col, wall.row, CellTypes.empty, null);
|
||||
if (this.grid_map.cellAt(wall.col, wall.row).state == CellStates.wall)
|
||||
this.changeCell(wall.col, wall.row, CellStates.empty, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class WorldEnvironment extends Environment{
|
||||
|
||||
reset(clear_walls=true) {
|
||||
this.organisms = [];
|
||||
this.grid_map.fillGrid(CellTypes.empty);
|
||||
this.grid_map.fillGrid(CellStates.empty);
|
||||
this.renderer.renderFullGrid(this.grid_map.grid);
|
||||
this.total_mutability = 0;
|
||||
this.OriginOfLife();
|
||||
|
||||
Reference in New Issue
Block a user