Merge pull request #85 from MaxRobinsonTheGreat/random-orgs
Random orgs
This commit is contained in:
22
Changelog.md
22
Changelog.md
@@ -3,23 +3,29 @@
|
|||||||
## 1.0.2 (current development)
|
## 1.0.2 (current development)
|
||||||
|
|
||||||
### UI Enhancements:
|
### UI Enhancements:
|
||||||
- New tab for world controls
|
- New tab "World Controls"
|
||||||
- Relocated grid controls, auto reset to this tab
|
- Relocated grid controls and auto reset to this tab
|
||||||
- Button to generate random walls with perlin noise
|
- Button to generate random walls with perlin noise
|
||||||
- Options for starting state, including simple producer and empty state
|
- Button to reset the environment with many randomly generated organisms
|
||||||
- Option to not clear walls when resetting
|
- Option to not clear walls on reset
|
||||||
- Option to pause on total extinction
|
- Option to pause on total extinction
|
||||||
- Combined `Movers can rotate` and `Offspring rotate` simulation controls into `Rotation enabled`
|
- "Simulation controls" tab renamed to "Evolution Controls"
|
||||||
- Can now drag view while rendering is off
|
- Button to save/load Evolution Controls in a `.json` file
|
||||||
|
- Button to randomize the organism in the editor window
|
||||||
|
- Can now use drag view tool while rendering is off
|
||||||
|
- Reorganized "About" tab and left panel, embedded explanation video
|
||||||
|
|
||||||
### Simulation Enhancements:
|
### Simulation Enhancements:
|
||||||
-
|
- New evolution control `Extra Mover Reproduction Cost`, which adds additional food cost for movers to reproduce
|
||||||
|
- Combined `Movers can rotate` and `Offspring rotate` evolution controls into `Rotation enabled`
|
||||||
|
- Fully max out simulation speed when slider is all the way to the right
|
||||||
|
|
||||||
### Bug Fixes:
|
### Bug Fixes:
|
||||||
- Armor is no longer ignored when checking for clear reproduction space
|
- Armor is no longer ignored when checking for clear reproduction space
|
||||||
|
- Chart data is now properly loaded/discarded when paused
|
||||||
|
|
||||||
|
|
||||||
Thanks to contributors:
|
Thanks to contributors: @Chrispykins @M4YX0R
|
||||||
|
|
||||||
## 1.0.1 (12/4/2021)
|
## 1.0.1 (12/4/2021)
|
||||||
|
|
||||||
|
|||||||
4
dist/css/style.css
vendored
4
dist/css/style.css
vendored
@@ -275,4 +275,8 @@ button:active{
|
|||||||
margin: auto;
|
margin: auto;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#reset-with-editor-org{
|
||||||
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
43
dist/index.html
vendored
43
dist/index.html
vendored
@@ -42,9 +42,8 @@
|
|||||||
<p class='tabnav-item open-tab' id='about'>About</p>
|
<p class='tabnav-item open-tab' id='about'>About</p>
|
||||||
<p class='tabnav-item' id='editor'>Editor</p>
|
<p class='tabnav-item' id='editor'>Editor</p>
|
||||||
<p class='tabnav-item' id='world-controls'>World Controls</p>
|
<p class='tabnav-item' id='world-controls'>World Controls</p>
|
||||||
<p class='tabnav-item' id='hyperparameters'>Simulation Controls</p>
|
<p class='tabnav-item' id='hyperparameters'>Evolution Controls</p>
|
||||||
<p class='tabnav-item' id='stats'>Statistics</p>
|
<p class='tabnav-item' id='stats'>Statistics</p>
|
||||||
<!-- <p class='tabnav-item' id='challenges'>Challenges</p> -->
|
|
||||||
<button id="minimize" title="Minimze Control Panel."><i class="fa fa-minus-square"></i></button>
|
<button id="minimize" title="Minimze Control Panel."><i class="fa fa-minus-square"></i></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -96,6 +95,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button id='clear-editor'>Clear</button>
|
<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>
|
</div>
|
||||||
@@ -125,7 +126,7 @@
|
|||||||
<label for="mutation-rate-edit" title='Probability that offspring of this organism will mutate'>Mutation Rate:</label>
|
<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">
|
<input type="number" id="mutation-rate-edit" min="1" max="100" value=3 step="1">
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<!-- <br> -->
|
||||||
<div class='brain-details'>
|
<div class='brain-details'>
|
||||||
<h4>Brain</h4>
|
<h4>Brain</h4>
|
||||||
<label for="observation-type-edit">Observation: </label>
|
<label for="observation-type-edit">Observation: </label>
|
||||||
@@ -150,7 +151,8 @@
|
|||||||
<p class='retreat-types'>Move Away From: killer</p>
|
<p class='retreat-types'>Move Away From: killer</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button id='reset-with-editor-org' title='Reset the environment with the organism in the editor'>Reset with Editor Organism</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id='world-controls' class='tab'>
|
<div id='world-controls' class='tab'>
|
||||||
@@ -166,23 +168,20 @@
|
|||||||
<label for="row-input">Rows:</label>
|
<label for="row-input">Rows:</label>
|
||||||
<input type="number" class="grid-size-in" id="row-input" min="1" value=100 step="1">
|
<input type="number" class="grid-size-in" id="row-input" min="1" value=100 step="1">
|
||||||
</div>
|
</div>
|
||||||
<br>
|
|
||||||
<button id='resize'>Resize and Reset</button>
|
<button id='resize'>Resize and Reset</button>
|
||||||
<h3>Reset Options</h3>
|
<h3>Reset Options</h3>
|
||||||
<label for="start-state">Starting state:</label>
|
|
||||||
<select name="start-state" id="start-state">
|
|
||||||
<option value="simple-prod">Simple producer</option>
|
|
||||||
<option value="rand-orgs">Random organisms</option>
|
|
||||||
<option value="no-orgs">No organisms</option>
|
|
||||||
</select> <br>
|
|
||||||
<label for="auto-reset">Reset on total extinction</label>
|
<label for="auto-reset">Reset on total extinction</label>
|
||||||
<input type="checkbox" id="auto-reset" checked>
|
<input type="checkbox" id="auto-reset" checked>
|
||||||
<p id='reset-count'>Auto reset count: </p>
|
<p id='reset-count'>Auto reset count: </p>
|
||||||
<label for="auto-pause" title='Will override reset on extinction'>Pause on total extinction</label>
|
<label for="auto-pause" title='Will override reset on extinction'>Pause on total extinction</label>
|
||||||
<input type="checkbox" id="auto-pause">
|
<input type="checkbox" id="auto-pause">
|
||||||
<br>
|
<br>
|
||||||
|
<button class='randomize-button reset-random' title="Generate many random organisms in the world.">Reset with Random Organisms</button>
|
||||||
|
<label for="num-random-orgs" title='Number of random organisms to generate'>Num to generate:</label>
|
||||||
|
<input type="number" id="num-random-orgs" min="1" value=100 step="1">
|
||||||
</div>
|
</div>
|
||||||
<div class='right-half'>
|
<div class='right-half'>
|
||||||
|
<br>
|
||||||
<button id='random-walls' title="Generates random walls.">Generate random walls</button> <br>
|
<button id='random-walls' title="Generates random walls.">Generate random walls</button> <br>
|
||||||
<button id="clear-walls" title="Clear All Walls. Hotkey: B">Clear all walls</button>
|
<button id="clear-walls" title="Clear All Walls. Hotkey: B">Clear all walls</button>
|
||||||
<br>
|
<br>
|
||||||
@@ -192,7 +191,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id='hyperparameters' class='tab'>
|
<div id='hyperparameters' class='tab'>
|
||||||
<div class='left-half'>
|
<div class='left-half'>
|
||||||
<h2>Simulation Controls</h2>
|
<h2>Evolution Controls</h2>
|
||||||
<label for="food-prod-prob" title='The probability that a producer cell will produce food each tick.'>Probability of producing food:</label>
|
<label for="food-prod-prob" title='The probability that a producer cell will produce food each tick.'>Probability of producing food:</label>
|
||||||
<input type="number" id="food-prod-prob" min=".001" max="100" value=4 step="1">
|
<input type="number" id="food-prod-prob" min=".001" max="100" value=4 step="1">
|
||||||
<br>
|
<br>
|
||||||
@@ -236,8 +235,8 @@
|
|||||||
<label for="food-blocks" title='When on, reproduction will fail if offspring intersect with food. When off, offspring will remove blocking food.'>Food blocks reproduction</label>
|
<label for="food-blocks" title='When on, reproduction will fail if offspring intersect with food. When off, offspring will remove blocking food.'>Food blocks reproduction</label>
|
||||||
<input type="checkbox" id="food-blocks" checked>
|
<input type="checkbox" id="food-blocks" checked>
|
||||||
<br>
|
<br>
|
||||||
<button id='save-controls'>Save</button>
|
<button id='save-controls' title="Save all Evolution Controls in a .json file">Save & Download</button>
|
||||||
<button id='load-controls'>Load</button>
|
<button id='load-controls' title="Load saved Evolution Controls with a .json file">Load</button>
|
||||||
<a id="download-el" style="display: none;"></a>
|
<a id="download-el" style="display: none;"></a>
|
||||||
<input id="upload-el" style="display: none;" type="file">
|
<input id="upload-el" style="display: none;" type="file">
|
||||||
</div>
|
</div>
|
||||||
@@ -264,22 +263,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id='challenges' class='tab'>
|
|
||||||
<div class='left-half'>
|
|
||||||
<h2>Challenges</h2>
|
|
||||||
<button class='challenge-btn' value='Without editing any organisms, evolve a static producer organism with 15 cells. '>Megaflora</button>
|
|
||||||
<button class='challenge-btn' value='Without editing any organisms, evolve a mover organism with 10 cells.'>Megafauna</button>
|
|
||||||
<button class='challenge-btn' value='Use the editor to create a new organism that dominates the current ecosystem and causes many species to go extinct.'>Invasive Species</button>
|
|
||||||
<button class='challenge-btn' value='Either through editing or evolving, create two different species that have a mutually beneficial relationship.'>Symbiosis</button>
|
|
||||||
<button class='challenge-btn' value='Evolve a stable ecosystem with 10 significantly different species.'>Biodiversity</button>
|
|
||||||
<button class='challenge-btn' value='Evolve a stable ecosystem without any killer cells.'>Utopia</button>
|
|
||||||
</div>
|
|
||||||
<div class='right-half'>
|
|
||||||
<h2 id='challenge-title'>Select a Challenge</h2>
|
|
||||||
<br>
|
|
||||||
<p id='challenge-description'>Challenge yourself to create interesting ecosystems and organisms. There is no formal way to win or lose, its just for fun! </p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='hot-controls'>
|
<div class='hot-controls'>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const Modes = {
|
|||||||
Select: 4,
|
Select: 4,
|
||||||
Edit: 5,
|
Edit: 5,
|
||||||
Clone: 6,
|
Clone: 6,
|
||||||
Drag: 7
|
Drag: 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Modes;
|
module.exports = Modes;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
const Hyperparams = require("../Hyperparameters");
|
const Hyperparams = require("../Hyperparameters");
|
||||||
const Modes = require("./ControlModes");
|
const Modes = require("./ControlModes");
|
||||||
const StatsPanel = require("../Stats/StatsPanel");
|
const StatsPanel = require("../Stats/StatsPanel");
|
||||||
|
const RandomOrganismGenerator = require("../Organism/RandomOrganismGenerator")
|
||||||
const WorldConfig = require("../WorldConfig");
|
const WorldConfig = require("../WorldConfig");
|
||||||
|
|
||||||
class ControlPanel {
|
class ControlPanel {
|
||||||
@@ -13,7 +14,6 @@ class ControlPanel {
|
|||||||
this.defineHyperparameterControls();
|
this.defineHyperparameterControls();
|
||||||
this.defineWorldControls();
|
this.defineWorldControls();
|
||||||
this.defineModeControls();
|
this.defineModeControls();
|
||||||
this.defineChallenges();
|
|
||||||
this.fps = engine.fps;
|
this.fps = engine.fps;
|
||||||
this.organism_record=0;
|
this.organism_record=0;
|
||||||
this.env_controller = this.engine.env.controller;
|
this.env_controller = this.engine.env.controller;
|
||||||
@@ -124,17 +124,12 @@ class ControlPanel {
|
|||||||
let text = this.fps >= max_fps ? 'MAX' : this.fps;
|
let text = this.fps >= max_fps ? 'MAX' : this.fps;
|
||||||
$('#fps').text("Target FPS: "+text);
|
$('#fps').text("Target FPS: "+text);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
$('.pause-button').click(function() {
|
$('.pause-button').click(function() {
|
||||||
$('.pause-button').find("i").toggleClass("fa fa-pause");
|
// toggle pause
|
||||||
$('.pause-button').find("i").toggleClass("fa fa-play");
|
this.setPaused(this.engine.running);
|
||||||
this.paused = !this.paused;
|
|
||||||
if (this.engine.running) {
|
|
||||||
this.engine.stop();
|
|
||||||
}
|
|
||||||
else if (!this.engine.running){
|
|
||||||
this.engine.start(this.fps);
|
|
||||||
}
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
$('.headless').click(function() {
|
$('.headless').click(function() {
|
||||||
$('.headless').find("i").toggleClass("fa fa-eye");
|
$('.headless').find("i").toggleClass("fa fa-eye");
|
||||||
$('.headless').find("i").toggleClass("fa fa-eye-slash");
|
$('.headless').find("i").toggleClass("fa fa-eye-slash");
|
||||||
@@ -202,11 +197,15 @@ class ControlPanel {
|
|||||||
});
|
});
|
||||||
$('#clear-walls-reset').change(function() {
|
$('#clear-walls-reset').change(function() {
|
||||||
WorldConfig.clear_walls_on_reset = this.checked;
|
WorldConfig.clear_walls_on_reset = this.checked;
|
||||||
})
|
});
|
||||||
|
$('#reset-with-editor-org').click( () => {
|
||||||
$('#start-state').change ( function() {
|
let env = this.engine.env;
|
||||||
WorldConfig.start_state = $("#start-state").val();
|
if (!env.reset(true, false)) return;
|
||||||
}.bind(this));
|
let center = env.grid_map.getCenter();
|
||||||
|
let org = this.editor_controller.env.getCopyOfOrg();
|
||||||
|
this.env_controller.add_new_species = true;
|
||||||
|
this.env_controller.dropOrganism(org, center[0], center[1])
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
defineHyperparameterControls() {
|
defineHyperparameterControls() {
|
||||||
@@ -230,7 +229,6 @@ class ControlPanel {
|
|||||||
Hyperparams.foodDropProb = $('#food-drop-rate').val();
|
Hyperparams.foodDropProb = $('#food-drop-rate').val();
|
||||||
});
|
});
|
||||||
$('#extra-mover-cost').change(function() {
|
$('#extra-mover-cost').change(function() {
|
||||||
console.log(parseInt($('#extra-mover-cost').val()))
|
|
||||||
Hyperparams.extraMoverFoodCost = parseInt($('#extra-mover-cost').val());
|
Hyperparams.extraMoverFoodCost = parseInt($('#extra-mover-cost').val());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -359,7 +357,6 @@ class ControlPanel {
|
|||||||
$('.edit-mode-btn').removeClass('selected');
|
$('.edit-mode-btn').removeClass('selected');
|
||||||
$('.'+this.id).addClass('selected');
|
$('.'+this.id).addClass('selected');
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.reset-view').click( function(){
|
$('.reset-view').click( function(){
|
||||||
this.env_controller.resetView();
|
this.env_controller.resetView();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
@@ -382,7 +379,14 @@ class ControlPanel {
|
|||||||
$('#clear-editor').click( function() {
|
$('#clear-editor').click( function() {
|
||||||
this.engine.organism_editor.clear();
|
this.engine.organism_editor.clear();
|
||||||
this.editor_controller.setEditorPanel();
|
this.editor_controller.setEditorPanel();
|
||||||
}.bind(this))
|
}.bind(this));
|
||||||
|
$('#generate-random').click( function() {
|
||||||
|
this.engine.organism_editor.createRandom();
|
||||||
|
this.editor_controller.refreshDetailsPanel();
|
||||||
|
}.bind(this));
|
||||||
|
$('.reset-random').click( function() {
|
||||||
|
this.engine.organism_editor.resetWithRandomOrgs(this.engine.env);
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
window.onbeforeunload = function (e) {
|
window.onbeforeunload = function (e) {
|
||||||
e = e || window.event;
|
e = e || window.event;
|
||||||
@@ -394,11 +398,22 @@ class ControlPanel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
defineChallenges() {
|
setPaused(paused) {
|
||||||
$('.challenge-btn').click(function() {
|
|
||||||
$('#challenge-title').text($(this).text());
|
if (paused) {
|
||||||
$('#challenge-description').text($(this).val());
|
|
||||||
});
|
$('.pause-button').find("i").removeClass("fa-pause");
|
||||||
|
$('.pause-button').find("i").addClass("fa-play");
|
||||||
|
if (this.engine.running)
|
||||||
|
this.engine.stop();
|
||||||
|
}
|
||||||
|
else if (!paused) {
|
||||||
|
|
||||||
|
$('.pause-button').find("i").addClass("fa-pause");
|
||||||
|
$('.pause-button').find("i").removeClass("fa-play");
|
||||||
|
if (!this.engine.running)
|
||||||
|
this.engine.start(this.fps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMode(mode) {
|
setMode(mode) {
|
||||||
@@ -429,7 +444,7 @@ class ControlPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateHeadlessIcon(delta_time) {
|
updateHeadlessIcon(delta_time) {
|
||||||
if (this.paused)
|
if (!this.engine.running)
|
||||||
return;
|
return;
|
||||||
const min_opacity = 0.4;
|
const min_opacity = 0.4;
|
||||||
var op = this.headless_opacity + (this.opacity_change_rate*delta_time/1000);
|
var op = this.headless_opacity + (this.opacity_change_rate*delta_time/1000);
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class EditorController extends CanvasController{
|
|||||||
clearDetailsPanel() {
|
clearDetailsPanel() {
|
||||||
$('#organism-details').css('display', 'none');
|
$('#organism-details').css('display', 'none');
|
||||||
$('#edit-organism-details').css('display', 'none');
|
$('#edit-organism-details').css('display', 'none');
|
||||||
|
$('#randomize-organism-details').css('display', 'none');
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshDetailsPanel() {
|
refreshDetailsPanel() {
|
||||||
@@ -213,6 +214,11 @@ class EditorController extends CanvasController{
|
|||||||
var reaction = this.env.organism.brain.decisions[name];
|
var reaction = this.env.organism.brain.decisions[name];
|
||||||
$('#reaction-edit').val(reaction);
|
$('#reaction-edit').val(reaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setRandomizePanel() {
|
||||||
|
this.clearDetailsPanel();
|
||||||
|
$('#randomize-organism-details').css('display', 'block');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = EditorController;
|
module.exports = EditorController;
|
||||||
|
|||||||
@@ -141,21 +141,7 @@ class EnvironmentController extends CanvasController{
|
|||||||
|
|
||||||
case Modes.Clone:
|
case Modes.Clone:
|
||||||
if (this.org_to_clone != null){
|
if (this.org_to_clone != null){
|
||||||
var new_org = new Organism(this.mouse_c, this.mouse_r, this.env, this.org_to_clone);
|
this.dropOrganism(this.org_to_clone, this.mouse_c, this.mouse_r);
|
||||||
if (this.add_new_species){
|
|
||||||
FossilRecord.addSpeciesObj(new_org.species);
|
|
||||||
new_org.species.start_tick = this.env.total_ticks;
|
|
||||||
this.add_new_species = false;
|
|
||||||
new_org.species.population = 0;
|
|
||||||
}
|
|
||||||
else if (this.org_to_clone.species.extinct){
|
|
||||||
FossilRecord.resurrect(this.org_to_clone.species);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_org.isClear(this.mouse_c, this.mouse_r)){
|
|
||||||
this.env.addOrganism(new_org);
|
|
||||||
new_org.species.addPop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Modes.Drag:
|
case Modes.Drag:
|
||||||
@@ -179,6 +165,29 @@ class EnvironmentController extends CanvasController{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dropOrganism(organism, col, row) {
|
||||||
|
|
||||||
|
// close the organism and drop it in the world
|
||||||
|
var new_org = new Organism(col, row, this.env, organism);
|
||||||
|
|
||||||
|
if (new_org.isClear(col, row)) {
|
||||||
|
if (this.add_new_species){
|
||||||
|
FossilRecord.addSpeciesObj(new_org.species);
|
||||||
|
new_org.species.start_tick = this.env.total_ticks;
|
||||||
|
this.add_new_species = false;
|
||||||
|
new_org.species.population = 0;
|
||||||
|
}
|
||||||
|
else if (this.org_to_clone.species.extinct){
|
||||||
|
FossilRecord.resurrect(this.org_to_clone.species);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.env.addOrganism(new_org);
|
||||||
|
new_org.species.addPop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
dropCellType(col, row, state, killBlocking=false) {
|
dropCellType(col, row, state, killBlocking=false) {
|
||||||
for (var loc of Neighbors.allSelf){
|
for (var loc of Neighbors.allSelf){
|
||||||
var c=col + loc[0];
|
var c=col + loc[0];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const Renderer = require('../Rendering/Renderer');
|
|||||||
const CellStates = require('../Organism/Cell/CellStates');
|
const CellStates = require('../Organism/Cell/CellStates');
|
||||||
const EditorController = require("../Controllers/EditorController");
|
const EditorController = require("../Controllers/EditorController");
|
||||||
const Species = require('../Stats/Species');
|
const Species = require('../Stats/Species');
|
||||||
|
const RandomOrganismGenerator = require('../Organism/RandomOrganismGenerator')
|
||||||
|
|
||||||
class OrganismEditor extends Environment{
|
class OrganismEditor extends Environment{
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -87,6 +88,31 @@ class OrganismEditor extends Environment{
|
|||||||
this.organism.updateGrid();
|
this.organism.updateGrid();
|
||||||
this.organism.species = new Species(this.organism.anatomy, null, 0);
|
this.organism.species = new Species(this.organism.anatomy, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createRandom() {
|
||||||
|
this.grid_map.fillGrid(CellStates.empty);
|
||||||
|
|
||||||
|
this.organism = RandomOrganismGenerator.generate(this);
|
||||||
|
this.organism.updateGrid();
|
||||||
|
this.organism.species = new Species(this.organism.anatomy, null, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
resetWithRandomOrgs(env) {
|
||||||
|
let reset_confirmed = env.reset(true, false);
|
||||||
|
if (!reset_confirmed) return;
|
||||||
|
let numOrganisms = parseInt($('#num-random-orgs').val());
|
||||||
|
|
||||||
|
let size = Math.ceil(8);
|
||||||
|
|
||||||
|
for (let i=0; i<numOrganisms; i++) {
|
||||||
|
let newOrganism = RandomOrganismGenerator.generate(this);
|
||||||
|
newOrganism.species = new Species(newOrganism.anatomy, null, 0);
|
||||||
|
var col = Math.floor(size + (Math.random() * (env.grid_map.cols-(size*2)) ) );
|
||||||
|
var row = Math.floor(size + (Math.random() * (env.grid_map.rows-(size*2)) ) );
|
||||||
|
env.controller.add_new_species = true;
|
||||||
|
env.controller.dropOrganism(newOrganism, col, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = OrganismEditor;
|
module.exports = OrganismEditor;
|
||||||
@@ -75,20 +75,12 @@ class WorldEnvironment extends Environment{
|
|||||||
|
|
||||||
OriginOfLife() {
|
OriginOfLife() {
|
||||||
var center = this.grid_map.getCenter();
|
var center = this.grid_map.getCenter();
|
||||||
switch (WorldConfig.start_state){
|
var org = new Organism(center[0], center[1], this);
|
||||||
case 'simple-prod':
|
org.anatomy.addDefaultCell(CellStates.mouth, 0, 0);
|
||||||
var org = new Organism(center[0], center[1], this);
|
org.anatomy.addDefaultCell(CellStates.producer, 1, 1);
|
||||||
org.anatomy.addDefaultCell(CellStates.mouth, 0, 0);
|
org.anatomy.addDefaultCell(CellStates.producer, -1, -1);
|
||||||
org.anatomy.addDefaultCell(CellStates.producer, 1, 1);
|
this.addOrganism(org);
|
||||||
org.anatomy.addDefaultCell(CellStates.producer, -1, -1);
|
FossilRecord.addSpecies(org, null);
|
||||||
this.addOrganism(org);
|
|
||||||
FossilRecord.addSpecies(org, null);
|
|
||||||
break;
|
|
||||||
case 'random-orgs':
|
|
||||||
break;
|
|
||||||
case 'no-orgs':
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addOrganism(organism) {
|
addOrganism(organism) {
|
||||||
@@ -146,7 +138,7 @@ class WorldEnvironment extends Environment{
|
|||||||
|
|
||||||
reset(confirm_reset=true, reset_life=true) {
|
reset(confirm_reset=true, reset_life=true) {
|
||||||
if (confirm_reset && !confirm('The current environment will be lost. Proceed?'))
|
if (confirm_reset && !confirm('The current environment will be lost. Proceed?'))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
this.organisms = [];
|
this.organisms = [];
|
||||||
this.grid_map.fillGrid(CellStates.empty, !WorldConfig.clear_walls_on_reset);
|
this.grid_map.fillGrid(CellStates.empty, !WorldConfig.clear_walls_on_reset);
|
||||||
@@ -156,7 +148,7 @@ class WorldEnvironment extends Environment{
|
|||||||
FossilRecord.clear_record();
|
FossilRecord.clear_record();
|
||||||
if (reset_life)
|
if (reset_life)
|
||||||
this.OriginOfLife();
|
this.OriginOfLife();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeGridColRow(cell_size, cols, rows) {
|
resizeGridColRow(cell_size, cols, rows) {
|
||||||
|
|||||||
@@ -91,6 +91,22 @@ class Anatomy {
|
|||||||
getRandomCell() {
|
getRandomCell() {
|
||||||
return this.cells[Math.floor(Math.random() * this.cells.length)];
|
return this.cells[Math.floor(Math.random() * this.cells.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNeighborsOfCell(col, row) {
|
||||||
|
|
||||||
|
var neighbors = [];
|
||||||
|
|
||||||
|
for (var x = -1; x <= 1; x++) {
|
||||||
|
for (var y = -1; y <= 1; y++) {
|
||||||
|
|
||||||
|
var neighbor = this.getLocalCell(col + x, row + y);
|
||||||
|
if (neighbor)
|
||||||
|
neighbors.push(neighbor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return neighbors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Anatomy;
|
module.exports = Anatomy;
|
||||||
@@ -95,6 +95,7 @@ const CellStates = {
|
|||||||
return this.living[Math.floor(Math.random() * this.living.length)];
|
return this.living[Math.floor(Math.random() * this.living.length)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CellStates.defineLists();
|
CellStates.defineLists();
|
||||||
|
|
||||||
module.exports = CellStates;
|
module.exports = CellStates;
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ class Organism {
|
|||||||
return cell != null && (cell.state == CellStates.empty || cell.owner == this || cell.owner == parent || cell.state == CellStates.food);
|
return cell != null && (cell.state == CellStates.empty || cell.owner == this || cell.owner == parent || cell.state == CellStates.food);
|
||||||
}
|
}
|
||||||
|
|
||||||
isClear(col, row, rotation=this.rotation, ignore_armor=false) {
|
isClear(col, row, rotation=this.rotation) {
|
||||||
for(var loccell of this.anatomy.cells) {
|
for(var loccell of this.anatomy.cells) {
|
||||||
var cell = this.getRealCell(loccell, col, row, rotation);
|
var cell = this.getRealCell(loccell, col, row, rotation);
|
||||||
if (cell==null) {
|
if (cell==null) {
|
||||||
|
|||||||
@@ -32,8 +32,12 @@ class Brain {
|
|||||||
this.decisions[CellStates.eye.name] = Decision.neutral;
|
this.decisions[CellStates.eye.name] = Decision.neutral;
|
||||||
}
|
}
|
||||||
|
|
||||||
randomizeDecisions() {
|
randomizeDecisions(randomize_all=false) {
|
||||||
// randomize the non obvious decisions
|
// randomize the non obvious decisions
|
||||||
|
if (randomize_all) {
|
||||||
|
this.decisions[CellStates.food.name] = Decision.getRandom();
|
||||||
|
this.decisions[CellStates.killer.name] = Decision.getRandom();
|
||||||
|
}
|
||||||
this.decisions[CellStates.mouth.name] = Decision.getRandom();
|
this.decisions[CellStates.mouth.name] = Decision.getRandom();
|
||||||
this.decisions[CellStates.producer.name] = Decision.getRandom();
|
this.decisions[CellStates.producer.name] = Decision.getRandom();
|
||||||
this.decisions[CellStates.mover.name] = Decision.getRandom();
|
this.decisions[CellStates.mover.name] = Decision.getRandom();
|
||||||
@@ -79,4 +83,6 @@ class Brain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Brain.Decision = Decision;
|
||||||
|
|
||||||
module.exports = Brain;
|
module.exports = Brain;
|
||||||
68
src/Organism/RandomOrganismGenerator.js
Normal file
68
src/Organism/RandomOrganismGenerator.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
const CellStates = require("./Cell/CellStates");
|
||||||
|
const Organism = require("./Organism");
|
||||||
|
const Brain = require("./Perception/Brain")
|
||||||
|
|
||||||
|
class RandomOrganismGenerator {
|
||||||
|
|
||||||
|
static generate(env) {
|
||||||
|
|
||||||
|
var center = env.grid_map.getCenter();
|
||||||
|
var organism = new Organism(center[0], center[1], env, null);
|
||||||
|
organism.anatomy.addDefaultCell(CellStates.mouth, 0, 0);
|
||||||
|
|
||||||
|
var outermostLayer = RandomOrganismGenerator.organismLayers;
|
||||||
|
var x, y;
|
||||||
|
|
||||||
|
// iterate from center to edge of organism
|
||||||
|
// layer 0 is the central cell of the organism
|
||||||
|
for (var layer = 1; layer <= outermostLayer; layer++) {
|
||||||
|
|
||||||
|
var someCellSpawned = false;
|
||||||
|
var spawnChance = RandomOrganismGenerator.cellSpawnChance * 1 - ((layer - 1) / outermostLayer);
|
||||||
|
|
||||||
|
// top
|
||||||
|
y = -layer;
|
||||||
|
for (x = -layer; x <= layer; x++)
|
||||||
|
someCellSpawned = RandomOrganismGenerator.trySpawnCell(organism, x, y, spawnChance);
|
||||||
|
|
||||||
|
// bottom
|
||||||
|
y = layer;
|
||||||
|
for (x = -layer; x <= layer; x++)
|
||||||
|
someCellSpawned = RandomOrganismGenerator.trySpawnCell(organism, x, y, spawnChance);
|
||||||
|
|
||||||
|
// left
|
||||||
|
x = -layer;
|
||||||
|
for (y = -layer + 1; y <= layer - 1; y++)
|
||||||
|
someCellSpawned = RandomOrganismGenerator.trySpawnCell(organism, x, y, spawnChance);
|
||||||
|
|
||||||
|
// right
|
||||||
|
x = layer;
|
||||||
|
for (y = -layer + 1; y < layer - 1; y++)
|
||||||
|
someCellSpawned = RandomOrganismGenerator.trySpawnCell(organism, x, y, spawnChance);
|
||||||
|
|
||||||
|
if (!someCellSpawned)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// randomize the organism's brain
|
||||||
|
organism.brain.randomizeDecisions(true);
|
||||||
|
|
||||||
|
return organism;
|
||||||
|
}
|
||||||
|
|
||||||
|
static trySpawnCell(organism, x, y, spawnChance) {
|
||||||
|
|
||||||
|
var neighbors = organism.anatomy.getNeighborsOfCell(x, y);
|
||||||
|
if (neighbors.length && Math.random() < spawnChance) {
|
||||||
|
organism.anatomy.addRandomizedCell(CellStates.getRandomLivingType(), x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RandomOrganismGenerator.organismLayers = 4;
|
||||||
|
RandomOrganismGenerator.cellSpawnChance = 0.75;
|
||||||
|
|
||||||
|
module.exports = RandomOrganismGenerator;
|
||||||
@@ -45,28 +45,33 @@ class ChartController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateData() {
|
updateData() {
|
||||||
var r_len = FossilRecord.tick_record.length;
|
let record_size = FossilRecord.tick_record.length;
|
||||||
var newest_t = -1;
|
let data_points = this.data[0].dataPoints;
|
||||||
var oldest_t = 0;
|
let newest_t = -1;
|
||||||
if (this.data[0].dataPoints.length>0) {
|
if (data_points.length>0) {
|
||||||
newest_t = this.data[0].dataPoints[this.data[0].dataPoints.length-1].x;
|
newest_t = this.data[0].dataPoints[data_points.length-1].x;
|
||||||
newest_t = this.data[0].dataPoints[0].x;
|
|
||||||
}
|
}
|
||||||
if (newest_t < FossilRecord.tick_record[r_len-1]) {
|
let to_add = 0;
|
||||||
this.addNewest();
|
let cur_t = FossilRecord.tick_record[record_size-1];
|
||||||
|
// first count up the number of new datapoints the chart is missing
|
||||||
|
while (cur_t !== newest_t) {
|
||||||
|
to_add++;
|
||||||
|
cur_t = FossilRecord.tick_record[record_size-to_add-1]
|
||||||
}
|
}
|
||||||
if (oldest_t < FossilRecord.tick_record[0]) {
|
// then add them in order
|
||||||
|
this.addNewest(to_add)
|
||||||
|
|
||||||
|
// remove oldest datapoints until the chart is the same size as the saved records
|
||||||
|
while (data_points.length > FossilRecord.tick_record.length) {
|
||||||
this.removeOldest();
|
this.removeOldest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewest() {
|
addNewest(to_add) {
|
||||||
var i = FossilRecord.tick_record.length-1;
|
for (let i=to_add; i>0; i--) {
|
||||||
this.addDataPoint(i);
|
let j = FossilRecord.tick_record.length-i;
|
||||||
}
|
this.addDataPoint(j);
|
||||||
|
}
|
||||||
addDataPoint(i) {
|
|
||||||
alert("Must override addDataPoint")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeOldest() {
|
removeOldest() {
|
||||||
@@ -75,6 +80,10 @@ class ChartController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addDataPoint(i) {
|
||||||
|
alert("Must override addDataPoint")
|
||||||
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this.data.length = 0;
|
this.data.length = 0;
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ const FossilRecord = {
|
|||||||
this.species_counts.push(this.extant_species.length);
|
this.species_counts.push(this.extant_species.length);
|
||||||
this.av_mut_rates.push(this.env.averageMutability());
|
this.av_mut_rates.push(this.env.averageMutability());
|
||||||
this.calcCellCountAverages();
|
this.calcCellCountAverages();
|
||||||
|
while (this.tick_record.length > this.record_size_limit) {
|
||||||
if (this.tick_record.length > this.record_size_limit) {
|
|
||||||
this.tick_record.shift();
|
this.tick_record.shift();
|
||||||
this.pop_counts.shift();
|
this.pop_counts.shift();
|
||||||
this.species_counts.shift();
|
this.species_counts.shift();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const WorldConfig = {
|
const WorldConfig = {
|
||||||
headless: false,
|
headless: false,
|
||||||
clear_walls_on_reset: false,
|
clear_walls_on_reset: false,
|
||||||
start_state: 'simple-prod',
|
|
||||||
auto_reset: true,
|
auto_reset: true,
|
||||||
auto_pause: false,
|
auto_pause: false,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user