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
1 change: 1 addition & 0 deletions F
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Organism Cells are only found in organisms, and cannot exist on their own in the
- Killer - Red, harms organisms in directly adjacent cells (besides itself).
- Armor - Purple, negates the effects of killer cells.
- Eye - Light purple with a slit, allows the organism to see and move intelligently. See further description below.
- Fin - Yellow, Allows creature to swim in water.

## Organisms
Organisms are structures of cells that eat food, reproduce, and die.
Expand Down
3 changes: 3 additions & 0 deletions dist/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ button:active{
#clear-walls {
margin-top: 5px;
}
#clear-water {
margin-top: 5px;
}
#organism-options {
display: none;
}
Expand Down
15 changes: 14 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
<button class="edit-mode-btn drag-view selected" id="drag-view" title="Drag View. Hotkey: S"><i class="fa fa-arrows"></i></button>
<button class="edit-mode-btn wall-drop" id="wall-drop" title="Drop/Remove Wall. Hotkey: D"><i class="fa fa-square"></i></button>
<button class="edit-mode-btn food-drop" id="food-drop" title="Drop/Remove Food. Hotkey: F"><i class="fa fa-cutlery"></i></button>
<button class="edit-mode-btn water-drop" id="water-drop" title="Drop/Remove Water"><i class="fa fa-tint"></i></button>
<button class="edit-mode-btn click-kill" id="click-kill" title="Click to kill. Hotkey: G"><i class="fa fa-bolt"></i></button>
<button id="clear-walls" title="Clear All Walls. Hotkey: B"><i class="fa fa-window-close"></i></button>
<button id="clear-walls" title="Clear All Walls. Hotkey: B"><i class="fa fa-window-close"></i></button>
<button id="clear-water" title="Clear All Water"><i class="fa fa-window-close"></i></button>

</div>
<h2>Simulation Speed</h2>
<input id="slider" type="range" min="1" max="300" value="60">
Expand Down Expand Up @@ -78,11 +81,13 @@ <h4>Cell Types</h4>
<div class='cell-legend-type' id='mouth' title="Mouth: Eats adjacent food."></div>
<div class='cell-legend-type' id='producer' title="Producer: Produces adjacent food."></div>
<div class='cell-legend-type' id='mover' title="Mover: Allows for movement and rotation."></div>
<div class='cell-legend-type' id='fin' title="Fin: Allows movement in water."></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='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='water' title="Water: Not part of an organism. Blocks movement and reproduction unless organism has fins."></div>
</div>
<br>
<p>Hover over each color to learn what it does. For a more in depth explanation of the simulation, view the
Expand Down Expand Up @@ -110,6 +115,7 @@ <h4>Cell Types</h4>
<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='fin' title="Fin: Allows movement in water."></div>
</div>
<div style='grid-column: 2;'>
<div class='cell-type' id='killer' title="Killer: Harms organisms in adjacent cells."></div>
Expand All @@ -126,6 +132,7 @@ <h4>Cell Types</h4>
<h3>Organism Details</h3>
<p class='cell-count'>Cell count: </p>
<p id='move-range'>Move Range: </p>
<p id='is-aquatic'>Is Aquatic: </p>
<p id='mutation-rate'>Mutation Rate: </p>
<br>

Expand All @@ -143,6 +150,10 @@ <h3>Edit Organism</h3>
<label for="move-range-edit" title='The number of cells to move before randomly changing direction. Overriden by brain decisions.'>Move Range:</label>
<input type="number" id="move-range-edit" min="1" max="100" value=3 step="1">
</div>
<div id='is-aquatic-cont'>
<label for="is-aquatic-edit" title='Can the organism only move in water?'>Is Aquatic:</label>
<input type="checkbox" id="is-aquatic-edit">
</div>
<div id='mutation-rate-cont'>
<label for="mutation-rate-edit" title='Probability that offspring of this organism will mutate'>Mutation Rate:</label>
<input type="number" id="mutation-rate-edit" min="1" max="100" value=3 step="1">
Expand All @@ -156,6 +167,7 @@ <h4>Brain</h4>
<option value="mouth">mouth</option>
<option value="producer">producer</option>
<option value="mover">mover</option>
<option value="fin">fin</option>
<option value="killer">killer</option>
<option value="armor">armor</option>
<option value="eye">eye</option>
Expand Down Expand Up @@ -269,6 +281,7 @@ <h2 id='challenge-title'>Select a Challenge</h2>
<button class="edit-mode-btn drag-view selected" id="drag-view" title="Drag View. Hotkey: S"><i class="fa fa-arrows"></i></button>
<button class="edit-mode-btn wall-drop" id="wall-drop" title="Drop/Remove Wall. Hotkey: D"><i class="fa fa-square"></i></button>
<button class="edit-mode-btn food-drop" id="food-drop" title="Drop/Remove Food. Hotkey: F"><i class="fa fa-cutlery"></i></button>
<button class="edit-mode-btn water-drop" id="water-drop" title="Drop/Remove Water"><i class="fa fa-tint"></i></button>
<button class="edit-mode-btn click-kill" id="click-kill" title="Click to kill. Hotkey: G"><i class="fa fa-bolt"></i></button>
<button class="headless" title="Toggle rendering. Hotkey: H"><i class="fa fa-eye-slash"></i></button>
<button class='pause-button' title="Play/Pause. Hotkey: Spacebar"><i class="fa fa-pause"></i></button>
Expand Down
3 changes: 2 additions & 1 deletion src/Controllers/ControlModes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const Modes = {
Select: 4,
Edit: 5,
Clone: 6,
Drag: 7
Drag: 7,
WaterDrop: 8,
}

module.exports = Modes;
8 changes: 8 additions & 0 deletions src/Controllers/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ class ControlPanel {
case "wall-drop":
self.setMode(Modes.WallDrop);
break;
case "water-drop":
self.setMode(Modes.WaterDrop);
break;
case "click-kill":
self.setMode(Modes.ClickKill);
break;
Expand Down Expand Up @@ -323,6 +326,11 @@ class ControlPanel {
if (confirm("Are you sure you want to clear all the walls?")) {
this.engine.env.clearWalls();
}
}.bind(this));
$('#clear-water').click( function() {
if (confirm("Are you sure you want to clear all the water?")) {
this.engine.env.clearWater();
}
}.bind(this));
$('#clear-editor').click( function() {
this.engine.organism_editor.clear();
Expand Down
35 changes: 29 additions & 6 deletions src/Controllers/EditorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class EditorController extends CanvasController{
}
else if (this.right_click)
this.env.removeCellFromOrg(this.mouse_c, this.mouse_r);

this.new_species = true;
this.setBrainPanelVisibility();
this.setMoveRangeVisibility();
this.setAquaticVisibility()
this.updateDetails();
}

Expand All @@ -68,6 +69,9 @@ class EditorController extends CanvasController{
case "mover":
self.edit_cell_type = CellStates.mover;
break;
case "fin":
self.edit_cell_type = CellStates.fin;
break;
case "killer":
self.edit_cell_type = CellStates.killer;
break;
Expand All @@ -93,9 +97,9 @@ class EditorController extends CanvasController{
$('#move-range-edit').change ( function() {
this.env.organism.move_range = parseInt($('#move-range-edit').val());
}.bind(this));
$('#mutation-rate-edit').change ( function() {
this.env.organism.mutability = parseInt($('#mutation-rate-edit').val());

$('#is-aquatic-edit').change(function() {
this.env.organism.is_aquatic = $('#is-aquatic-edit').is(":checked");
}.bind(this));
$('#observation-type-edit').change ( function() {
this.setBrainEditorValues($('#observation-type-edit').val());
Expand Down Expand Up @@ -127,9 +131,10 @@ class EditorController extends CanvasController{

$('.cell-count').text("Cell count: "+org.anatomy.cells.length);
$('#move-range').text("Move Range: "+org.move_range);
$('#is-aquatic').text("Is Aquatic: "+org.is_aquatic);

$('#mutation-rate').text("Mutation Rate: "+org.mutability);

if (Hyperparams.useGlobalMutability) {
if (Hyperparams.useGlobalMutability) {
$('#mutation-rate').css('display', 'none');
}
else {
Expand All @@ -154,6 +159,10 @@ class EditorController extends CanvasController{
$('#move-range-edit').val(org.move_range);
}

if (this.setAquaticVisibility()){
$('#is-aquatic-edit').val(org.is_aquatic);
}

$('#mutation-rate-edit').val(org.mutability);
if (Hyperparams.useGlobalMutability) {
$('#mutation-rate-cont').css('display', 'none');
Expand Down Expand Up @@ -208,6 +217,20 @@ class EditorController extends CanvasController{
return false;
}

setAquaticVisibility() {
var org = this.env.organism;

if (org.anatomy.has_fins) {
$('#is-aquatic-cont').css('display', 'block');
$('#is-aquatic').css('display', 'block');
return true;
}
org.is_aquatic = false
$('#is-aquatic-cont').css('display', 'none');
$('#is-aquatic').css('display', 'none');
return false;
}

setBrainEditorValues(name) {
$('#observation-type-edit').val(name);
var reaction = this.env.organism.brain.decisions[name];
Expand Down
22 changes: 22 additions & 0 deletions src/Controllers/EnvironmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ class EnvironmentController extends CanvasController{
this.dropCellType(cell.col, cell.row, CellStates.empty, false);
}
break;
case Modes.WaterDrop:
if (left_click){
this.env.water_map[cell.col][cell.row] = true
for (var loc of Neighbors.allSelf){
var c=cell.col + loc[0];
var r=cell.row + loc[1];
this.env.water_map[c][r] = true
}

this.dropCellType(cell.col, cell.row, CellStates.water, true);

}
else if (right_click){
this.env.water_map[cell.col][cell.row] = false
for (var loc of Neighbors.allSelf){
var c=cell.col + loc[0];
var r=cell.row + loc[1];
this.env.water_map[c][r] = false
}
this.dropCellType(cell.col, cell.row, CellStates.empty, false);
}
break;
case Modes.ClickKill:
this.killNearOrganisms();
break;
Expand Down
1 change: 1 addition & 0 deletions src/Environments/OrganismEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class OrganismEditor extends Environment{
var prev_cell = this.organism.anatomy.getLocalCell(loc_c, loc_r)
if (prev_cell != null) {
if (this.organism.anatomy.removeCell(loc_c, loc_r)) {

this.changeCell(c, r, CellStates.empty, null);
this.organism.species = new Species(this.organism.anatomy, null, 0);
}
Expand Down
39 changes: 35 additions & 4 deletions src/Environments/WorldEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class WorldEnvironment extends Environment{
super();
this.renderer = new Renderer('env-canvas', 'env', cell_size);
this.controller = new EnvironmentController(this, this.renderer.canvas);
var grid_rows = Math.ceil(this.renderer.height / cell_size);
var grid_cols = Math.ceil(this.renderer.width / cell_size);
this.grid_map = new GridMap(grid_cols, grid_rows, cell_size);
this.grid_rows = Math.ceil(this.renderer.height / cell_size);
this.grid_cols = Math.ceil(this.renderer.width / cell_size);
this.grid_map = new GridMap(this.grid_cols, this.grid_rows, cell_size);
this.organisms = [];
this.walls = [];
this.water = [];
this.water_map = [];
this.total_mutability = 0;
this.auto_reset = true;
this.largest_cell_count = 0;
Expand Down Expand Up @@ -69,6 +71,17 @@ class WorldEnvironment extends Environment{
}

OriginOfLife() {

for (var c = 0; c < this.grid_cols; c++) {
if(this.water_map[c] == null){
this.water_map[c] = []
}
for (var r = 0; r < this.grid_rows; r++) {
this.water_map[c][r] = false

}
}

var center = this.grid_map.getCenter();
var org = new Organism(center[0], center[1], this);
org.anatomy.addDefaultCell(CellStates.mouth, 0, 0);
Expand Down Expand Up @@ -96,10 +109,19 @@ class WorldEnvironment extends Environment{
}

changeCell(c, r, state, owner) {
if(state == CellStates.empty){
if(this.water_map[c][r] == true){
state = CellStates.water
}
}
super.changeCell(c, r, state, owner);
this.renderer.addToRender(this.grid_map.cellAt(c, r));
if(state == CellStates.wall)
this.walls.push(this.grid_map.cellAt(c, r));
if(state == CellStates.water){
this.water.push(this.grid_map.cellAt(c, r));
this.water_map[c][r] = true
}
}

clearWalls() {
Expand All @@ -109,6 +131,15 @@ class WorldEnvironment extends Environment{
}
}


clearWater() {
for(var water of this.water){
this.water_map[water.col][water.row] = false
if (this.grid_map.cellAt(water.col, water.row).state == CellStates.water)
this.changeCell(water.col, water.row, CellStates.empty, null);
}
}

clearOrganisms() {
for (var org of this.organisms)
org.die();
Expand All @@ -123,7 +154,7 @@ class WorldEnvironment extends Environment{
var c=Math.floor(Math.random() * this.grid_map.cols);
var r=Math.floor(Math.random() * this.grid_map.rows);

if (this.grid_map.cellAt(c, r).state == CellStates.empty){
if (this.grid_map.cellAt(c, r).state == CellStates.empty || this.grid_map.cellAt(c, r).state == CellStates.water){
this.changeCell(c, r, CellStates.food, null);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Organism/Anatomy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Anatomy {
this.cells = [];
this.is_producer = false;
this.is_mover = false;
this.has_fins = false;
this.has_eyes = false;
this.birth_distance = 4;
}
Expand Down Expand Up @@ -77,6 +78,7 @@ class Anatomy {
checkTypeChange() {
this.is_producer = false;
this.is_mover = false;
this.has_fins = false;
this.has_eyes = false;
for (var cell of this.cells) {
if (cell.state == CellStates.producer)
Expand All @@ -85,6 +87,8 @@ class Anatomy {
this.is_mover = true;
if (cell.state == CellStates.eye)
this.has_eyes = true;
if (cell.state == CellStates.fin)
this.has_fins = true;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Organism/Cell/BodyCells/BodyCellFactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const MouthCell = require("./MouthCell");
const ProducerCell = require("./ProducerCell");
const MoverCell = require("./MoverCell");
const FinCell = require("./FinCell");
const KillerCell = require("./KillerCell");
const ArmorCell = require("./ArmorCell");
const EyeCell = require("./EyeCell");
Expand All @@ -13,6 +14,7 @@ const BodyCellFactory = {
type_map[CellStates.mouth.name] = MouthCell;
type_map[CellStates.producer.name] = ProducerCell;
type_map[CellStates.mover.name] = MoverCell;
type_map[CellStates.fin.name] = FinCell;
type_map[CellStates.killer.name] = KillerCell;
type_map[CellStates.armor.name] = ArmorCell;
type_map[CellStates.eye.name] = EyeCell;
Expand Down
11 changes: 11 additions & 0 deletions src/Organism/Cell/BodyCells/FinCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const CellStates = require("../CellStates");
const BodyCell = require("./BodyCell");

class FinCell extends BodyCell{
constructor(org, loc_col, loc_row){
super(CellStates.fin, org, loc_col, loc_row);
this.org.anatomy.has_fins = true;
}
}

module.exports = FinCell;
2 changes: 1 addition & 1 deletion src/Organism/Cell/BodyCells/ProducerCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ProducerCell extends BodyCell{
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){
if (cell != null && (cell.state == CellStates.empty || (cell.state == CellStates.water && this.org.anatomy.has_fins))){
env.changeCell(real_c+loc_c, real_r+loc_r, CellStates.food, null);
return;
}
Expand Down
Loading