Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/*
dist/js/bundle.js
./package-lock.json
dist/*
./package-lock.json
.vscode/*
25 changes: 22 additions & 3 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ <h3>The Life Engine</h3>
<div class='cell-legend-type' id='mover' title="Mover: Allows for movement and rotation."></div>
<div class='cell-legend-type' id='killer' title="Killer: Harms organisms in adjacent cells."></div>
<div class='cell-legend-type' id='armor' title="Armor: Negates affects of killer cell."></div>
<div class='cell-legend-type' id='cool' title="Healer: Increases the age and decreases mutation chance of a organism."></div>
<div class='cell-legend-type' id='camo' title="Mimicker: Is seen as something else."></div>
<div class='cell-legend-type' id='parasitic' title="Parasite: Feeds off other organisms."></div>
<div class='cell-legend-type' id='eye' title="Eye: Observes cells and decides movement."></div>
<div class='cell-legend-type' id='food' title="Food: Not part of an organism. Once an organism has eaten enough food, it will reproduce."></div>
<div class='cell-legend-type' id='wall' title="Wall: Not part of an organism. Blocks movement and reproduction."></div>
<div class='cell-legend-type' id='secretion' title="Secretion: Secretes chemicals which is detected by the detector."></div>
<div class='cell-legend-type' id='detector' title="Detector: Detects chemicals."></div>
</div><br>
</div>
<div class='right-half'>
Expand Down Expand Up @@ -94,18 +99,26 @@ <h3>The Life Engine</h3>
<div class='cell-type' id='mouth' title="Mouth: Eats adjacent food."></div>
<div class='cell-type' id='producer' title="Producer: Produces adjacent food."></div>
<div class='cell-type' id='mover' title="Mover: Allows for movement and rotation."></div>
<div class='cell-type' id='cool' title="Healer: Increases the age and decreases mutation chance of a oraganism."></div>
</div>
<div style='grid-column: 2;'>
<div class='cell-type' id='killer' title="Killer: Harms organisms in adjacent cells."></div>
<div class='cell-type' id='armor' title="Armor: Negates affects of killer cell."></div>
<div class='cell-type' id='eye' title="Eye: Looks for cells to move away from or towards. Click again on a placed cell to rotate"></div>
<div class='cell-type' id='camo' title="Mimicker: Is seen as something else."></div>
</div>

<div style='grid-column: 3;'>
<div class='cell-type' id='parasitic' title="Parasite: Feeds off other organisms."></div>
<div class='cell-type' id='secretion' title="Secretor: Secretes."></div>
<div class='cell-type' id='detector' title="Detector: Detects."></div>
</div>
</div>
<div>
<button id='clear-editor'>Clear</button>
<button class='randomize-button' id='generate-random' title="Randomizes organism"><i class="fa fa-random"></i></button>
<br>
</div>

</div>
<div class='right-half'>
<div id='organism-details' style="display:none;">
Expand Down Expand Up @@ -145,7 +158,12 @@ <h4>Brain</h4>
<option value="mover">mover</option>
<option value="killer">killer</option>
<option value="armor">armor</option>
<option value="cool">cool</option>
<option value="camo">camo</option>
<option value="parasitic">parasitic</option>
<option value="eye">eye</option>
<option value="secretion">secretion</option>
<option value="detector">detector</option>
</select>

<label for="reaction-edit">Reaction: </label>
Expand Down Expand Up @@ -296,7 +314,8 @@ <h1>Community Creations</h1>
<div class="list-title-container">
<h2>🌍Worlds</h2>
<div id="worlds-list-container" class="list-container">
<ul id="worlds-list"></ul>
<ul id="worlds-list">
</ul>
</div>
</div>
<div class="list-title-container">
Expand Down
3,181 changes: 1,285 additions & 1,896 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Version 2 of the evolution simulator",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "mocha",
"build": "webpack --mode=production",
"build-dev": "webpack --mode=development",
"build-watch": "webpack --watch --mode=development"
Expand All @@ -21,12 +21,13 @@
},
"homepage": "https://github.com/MaxRobinsonTheGreat/EvolutionSimulatorV2#readme",
"devDependencies": {
"webpack": "^5.89.0",
"webpack-cli": "^3.3.12"
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"glob-parent": "^6.0.2",
"jquery": "^3.6.1",
"mocha": "^8.4.0",
"npm": "^10.2.1",
"watchpack": "^2.4.0"
}
Expand Down
50 changes: 37 additions & 13 deletions src/Controllers/EditorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,24 @@ class EditorController extends CanvasController{
case "armor":
self.edit_cell_type = CellStates.armor;
break;
case "cool":
self.edit_cell_type = CellStates.cool;
break;
case "camo":
self.edit_cell_type = CellStates.camo;
break;
case "eye":
self.edit_cell_type = CellStates.eye;
break;
case "parasitic":
self.edit_cell_type = CellStates.parasitic;
break;
case "detector":
self.edit_cell_type = CellStates.detector;
break;
case "secretion":
self.edit_cell_type = CellStates.secretion;
break;
}
$(".cell-type" ).css( "border-color", "black" );
var selected = '#'+this.id+'.cell-type';
Expand All @@ -95,27 +110,36 @@ class EditorController extends CanvasController{
defineEditorDetails() {
this.details_html = $('#organism-details');
this.edit_details_html = $('#edit-organism-details');

this.decision_names = ["ignore", "move away", "move towards"];

$('#move-range-edit').change ( function() {
$('#move-range-edit').change(() => {
this.env.organism.move_range = parseInt($('#move-range-edit').val());
}.bind(this));
$('#mutation-rate-edit').change ( function() {
});
$('#mutation-rate-edit').change(() => {
this.env.organism.mutability = parseInt($('#mutation-rate-edit').val());
}.bind(this));
$('#observation-type-edit').change ( function() {
});

$('#observation-type-edit').change(() => {
this.setBrainEditorValues($('#observation-type-edit').val());
this.setBrainDetails();
}.bind(this));
$('#reaction-edit').change ( function() {
var obs = $('#observation-type-edit').val();
var decision = parseInt($('#reaction-edit').val());
});

$('#reaction-edit').change(() => {
const obs = $('#observation-type-edit').val();
const decision = parseInt($('#reaction-edit').val());

// Ensure brain.decisions is initialized properly
if (!this.env.organism.brain.decisions || Array.isArray(this.env.organism.brain.decisions)) {
this.env.organism.brain.decisions = {}; // Reinitialize to an empty object
}

this.env.organism.brain.decisions[obs] = decision;
this.setBrainDetails();
}.bind(this));
});
}


defineSaveLoad() {
$('#save-org').click(()=>{
Expand Down
2 changes: 0 additions & 2 deletions src/Controllers/LoadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ const LoadController = {

async loadList(name) {
const base = `./assets/${name}/`;

let list = [];
try {
let resp = await fetch(base+'_list.json');
list = await resp.json();
} catch(e) {
console.error('Failed to load list: ', e);
}

let id = `#${name}-list`
$(id).empty();
for (let item of list) {
Expand Down
3 changes: 2 additions & 1 deletion src/Grid/GridMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class GridMap {
this.cols = cols;
this.rows = rows;
this.cell_size = cell_size;
let chemical = null;
for(var c=0; c<cols; c++) {
var row = [];
for(var r=0; r<rows; r++) {
var cell = new Cell(CellStates.empty, c, r, c*cell_size, r*cell_size);
var cell = new Cell(CellStates.empty, c, r, c*cell_size, r*cell_size, chemical);
row.push(cell);
}
this.grid.push(row);
Expand Down
3 changes: 3 additions & 0 deletions src/Hyperparameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Hyperparams = {
this.killableNeighbors = Neighbors.adjacent;
this.edibleNeighbors = Neighbors.adjacent;
this.growableNeighbors = Neighbors.adjacent;
this.hostNeighbors = Neighbors.adjacent;

this.useGlobalMutability = false;
this.globalMutability = 5;
Expand All @@ -26,6 +27,8 @@ const Hyperparams = {

this.foodDropProb = 0;

this.parasiticSteal = 100;

this.extraMoverFoodCost = 0;

this.maxOrganisms = -1;
Expand Down
9 changes: 9 additions & 0 deletions src/Organism/Anatomy.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ class Anatomy {
return neighbors;
}

countCellType(cellType) {
let count = 0;
for (let cell in this.cells) {
if (cell.state == cellType)
count++;
}
return count;
}

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) {
Expand Down
5 changes: 4 additions & 1 deletion src/Organism/Cell/BodyCells/BodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class BodyCell{
// default behavior: none
}


getRealCol() {
return this.org.c + this.rotatedCol(this.org.rotation);
}
Expand Down Expand Up @@ -73,6 +72,10 @@ class BodyCell{
return this.loc_col;
}
}

getStateName() {
return this.state.name;
}
}

module.exports = BodyCell;
11 changes: 11 additions & 0 deletions src/Organism/Cell/BodyCells/BodyCellFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ const ProducerCell = require("./ProducerCell");
const MoverCell = require("./MoverCell");
const KillerCell = require("./KillerCell");
const ArmorCell = require("./ArmorCell");
const CooldownCell = require("./CooldownCell");
const CamoCell = require("./CamoCell");
const EyeCell = require("./EyeCell");
const ParasiticCell = require("./ParasiticCell");
const DetectorCell = require("./DetectorCell");
const SecretionCell = require("./SecretionCell");
const CellStates = require("../CellStates");



const BodyCellFactory = {
init: function() {
var type_map = {};
Expand All @@ -15,6 +21,11 @@ const BodyCellFactory = {
type_map[CellStates.mover.name] = MoverCell;
type_map[CellStates.killer.name] = KillerCell;
type_map[CellStates.armor.name] = ArmorCell;
type_map[CellStates.cool.name] = CooldownCell;
type_map[CellStates.camo.name] = CamoCell;
type_map[CellStates.parasitic.name] = ParasiticCell;
type_map[CellStates.detector.name] = DetectorCell;
type_map[CellStates.secretion.name] = SecretionCell;
type_map[CellStates.eye.name] = EyeCell;
this.type_map = type_map;
},
Expand Down
40 changes: 40 additions & 0 deletions src/Organism/Cell/BodyCells/CamoCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const CellStates = require("../CellStates");
const BodyCell = require("./BodyCell");

class CamoCell extends BodyCell {
constructor(org, loc_col, loc_row) {
super(CellStates.camo, org, loc_col, loc_row);
}
initInherit(parent) {
// deep copy parent values
this.loc_col = parent.loc_col;
this.loc_row = parent.loc_row;
this.mimicryState = parent.mimicryState;
}
initRandom() {
this.mimicryState = CellStates.getRandomName();
while (this.mimicryState == 'camo')
this.mimicryState = CellStates.getRandomName();
}

initDefault() {
this.mimicryState = CellStates.getRandomName();
}

getStateName() {
return this.mimicryState;
}

performFunction() {
}

// used when mymicing an eye cell
getAbsoluteDirection() {
// change this later
return 0; // Directions.up
}

}


module.exports = CamoCell;
15 changes: 15 additions & 0 deletions src/Organism/Cell/BodyCells/CooldownCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const CellStates = require("../CellStates");
const BodyCell = require("./BodyCell");

class CooldownCell extends BodyCell {
constructor(org, loc_col, loc_row) {
super(CellStates.cool, org, loc_col, loc_row);
}

performFunction() {
this.org.heal()
}
}


module.exports = CooldownCell;
36 changes: 36 additions & 0 deletions src/Organism/Cell/BodyCells/DetectorCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// places a chemical/just a number below it
// add a function in world environment
const CellStates = require("../CellStates");
const BodyCell = require("./BodyCell");
const GridMap = require("../../.././Grid/GridMap");
// use cell at fucnction on Grid map then that variable do .chemical = ____

class DetectorCell extends BodyCell {
constructor(org, loc_col, loc_row){
super(CellStates.detector, org, loc_col, loc_row);
}
// in the constructor put a chemical thats inherited
initInherit(parent) {
// deep copy parent values
super.initInherit(parent);
this.chemical = parent.chemical;
}

initRandom() {
const nothing = 6
// initialize values randomly
this.chemical = Math.random()*nothing
}

performFunction() {
if (this.org.Brain) {
var env = this.org.env
let column = this.org.c + this.loc_col
let row = this.org.r + this.loc_row
let chemical = env.grid_map.cellAt(column, row).chemical
this.org.Brain.detect(chemical);
}
}
}

module.exports = DetectorCell;
Loading