27
Changelog.md
27
Changelog.md
@@ -1,5 +1,32 @@
|
||||
# Changelog
|
||||
|
||||
## 1.0.2 (12/21/2021)
|
||||
|
||||
### UI Enhancements:
|
||||
- New tab "World Controls"
|
||||
- Relocated grid controls and auto reset to this tab
|
||||
- Button to generate random walls with perlin noise
|
||||
- Button to reset the environment with many randomly generated organisms
|
||||
- Option to not clear walls on reset
|
||||
- Option to pause on total extinction
|
||||
- "Simulation controls" tab renamed to "Evolution Controls"
|
||||
- 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:
|
||||
- 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:
|
||||
- Armor is no longer ignored when checking for clear reproduction space
|
||||
- Chart data is now properly loaded/discarded when paused
|
||||
|
||||
|
||||
Thanks to contributors: @Chrispykins @M4YX0R
|
||||
|
||||
## 1.0.1 (12/4/2021)
|
||||
|
||||
### UI Enhancements:
|
||||
|
||||
32
dist/css/style.css
vendored
32
dist/css/style.css
vendored
@@ -57,11 +57,15 @@ body{
|
||||
|
||||
img {
|
||||
image-rendering: -moz-crisp-edges;
|
||||
image-rendering: -webkit-crisp-edges;
|
||||
image-rendering: pixelated;
|
||||
image-rendering: crisp-edges;
|
||||
width: 60%;
|
||||
image-rendering: -webkit-crisp-edges;
|
||||
image-rendering: pixelated;
|
||||
image-rendering: crisp-edges;
|
||||
object-fit: cover;
|
||||
width: 85%;
|
||||
max-width: 500px;
|
||||
max-height: 40%;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
button {
|
||||
@@ -75,6 +79,7 @@ button {
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
min-width: 30px;
|
||||
margin: 2px;
|
||||
}
|
||||
button:hover{
|
||||
background-color: #81d2c7;
|
||||
@@ -133,6 +138,10 @@ button:active{
|
||||
background-color: #81d2c7;
|
||||
color: black;
|
||||
}
|
||||
.open-tab {
|
||||
background-color: #66a39b;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.tab {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
@@ -255,4 +264,19 @@ button:active{
|
||||
}
|
||||
#maximize-hot-control {
|
||||
right: 10px;
|
||||
}
|
||||
|
||||
.grid-size-in {
|
||||
width: 75px;
|
||||
}
|
||||
|
||||
#video {
|
||||
height: 200px;
|
||||
margin: auto;
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
#reset-with-editor-org{
|
||||
margin-top: 5px;
|
||||
}
|
||||
127
dist/index.html
vendored
127
dist/index.html
vendored
@@ -24,56 +24,34 @@
|
||||
<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 selected" id="food-drop" title="Drop/Remove Food. Hotkey: F"><i class="fa fa-cutlery"></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>
|
||||
</div>
|
||||
<h2>Simulation Speed</h2>
|
||||
<img src="./img/title.png" alt="Life Engine">
|
||||
<h3>Simulation Speed</h3>
|
||||
<input id="slider" type="range" min="1" max="300" value="60">
|
||||
<button class='pause-button' title="Play/Pause. Hotkey: Spacebar"><i class="fa fa-pause"></i></button>
|
||||
<button class="headless" title="Toggle rendering. Hotkey: H"><i class="fa fa-eye-slash"></i></button>
|
||||
<p id='fps'>Target FPS: 60</p>
|
||||
<p id='fps-actual'></p>
|
||||
<button id='reset-env' title='Restarts simulation with default organism.'>Reset</button>
|
||||
<button id='clear-env' title="Removes all organisms and walls. Will disable 'reset on extinction'"">Clear</button>
|
||||
<br>
|
||||
<label for="auto-reset">Reset on total extinction</label>
|
||||
<input type="checkbox" id="auto-reset" checked>
|
||||
<br>
|
||||
<p id='reset-count'>Auto reset count: </p>
|
||||
<h3>Grid Size</h3>
|
||||
<label for="cell-size">Cell Size:</label>
|
||||
<input type="number" id="cell-size" min="1" max="100" value=5 step="1">
|
||||
<label for="fill-window">Fill Window</label>
|
||||
<input type="checkbox" id="fill-window" checked>
|
||||
<div class='col-row-input'>
|
||||
<label for="col-input">Columns:</label>
|
||||
<input type="number" id="col-input" min="1" value=100 step="1">
|
||||
<label for="row-input">Rows:</label>
|
||||
<input type="number" id="row-input" min="1" value=100 step="1">
|
||||
</div>
|
||||
<br>
|
||||
<button id='resize'>Resize and Reset</button>
|
||||
<button id='clear-env' title="Removes all organisms.">Clear</button>
|
||||
</div>
|
||||
|
||||
<div id='tab-container' class='control-set'>
|
||||
|
||||
<div class="tabnav">
|
||||
<p class='tabnav-item' 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='hyperparameters'>Simulation Controls</p>
|
||||
<p class='tabnav-item' id='stats'>Stats</p>
|
||||
<p class='tabnav-item' id='challenges'>Challenges</p>
|
||||
<p class='tabnav-item' id='world-controls'>World Controls</p>
|
||||
<p class='tabnav-item' id='hyperparameters'>Evolution Controls</p>
|
||||
<p class='tabnav-item' id='stats'>Statistics</p>
|
||||
<button id="minimize" title="Minimze Control Panel."><i class="fa fa-minus-square"></i></button>
|
||||
</div>
|
||||
|
||||
<div id='about' class='tab'>
|
||||
<div class='left-half'>
|
||||
<img src="./img/title.png" alt="Life Engine">
|
||||
<p>The Life Engine is a virtual ecosystem that allows organisms to grow, spread, and compete.</p>
|
||||
<p>Each organism is made up by a structure of cells, which provide different benefits based on their color.</p>
|
||||
|
||||
</div>
|
||||
<div class='right-half'>
|
||||
<h4>Cell Types</h4>
|
||||
<h3>The Life Engine</h3>
|
||||
<p>The Life Engine is a virtual ecosystem that allows organisms to reproduce, compete, and evolve.</p>
|
||||
<p>Each organism is made up of different colored cells. Hover over each color to learn what it does.</p>
|
||||
<div id='cell-legend'>
|
||||
<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>
|
||||
@@ -83,14 +61,13 @@
|
||||
<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>
|
||||
<br>
|
||||
<p>Hover over each color to learn what it does. For a more in depth explanation of the simulation, view the
|
||||
<a href="https://github.com/MaxRobinsonTheGreat/EvolutionSimulatorV2#readme">readme</a> and you can explore the source code.
|
||||
</p>
|
||||
</div><br>
|
||||
</div>
|
||||
<div class='right-half'>
|
||||
<iframe id="video" src="https://www.youtube.com/embed/iSAKEnRfles"></iframe>
|
||||
</div>
|
||||
<div class='icon-links'>
|
||||
<a href="https://www.youtube.com/channel/UCwBhBDsqiQflTMLy2epbQVw"><i class="fa fa-youtube"></i></a>
|
||||
<a href=https://github.com/MaxRobinsonTheGreat/EvolutionSimulatorV2 title='View the code'><i class="fa fa-github"></i></a>
|
||||
<a href="https://twitter.com/max_romana"><i class="fa fa-twitter"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -118,6 +95,8 @@
|
||||
</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>
|
||||
@@ -147,7 +126,7 @@
|
||||
<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">
|
||||
</div>
|
||||
<br>
|
||||
<!-- <br> -->
|
||||
<div class='brain-details'>
|
||||
<h4>Brain</h4>
|
||||
<label for="observation-type-edit">Observation: </label>
|
||||
@@ -172,23 +151,55 @@
|
||||
<p class='retreat-types'>Move Away From: killer</p>
|
||||
</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 id='world-controls' class='tab'>
|
||||
<div class='left-half'>
|
||||
<h3>Grid Size</h3>
|
||||
<label for="cell-size">Cell Size:</label>
|
||||
<input type="number" id="cell-size" min="1" max="100" value=5 step="1">
|
||||
<label for="fill-window">Fill Window</label>
|
||||
<input type="checkbox" id="fill-window" checked>
|
||||
<div class='col-row-input'>
|
||||
<label for="col-input">Columns:</label>
|
||||
<input type="number" class="grid-size-in" id="col-input" min="1" value=100 step="1">
|
||||
<label for="row-input">Rows:</label>
|
||||
<input type="number" class="grid-size-in" id="row-input" min="1" value=100 step="1">
|
||||
</div>
|
||||
<button id='resize'>Resize and Reset</button>
|
||||
<h3>Reset Options</h3>
|
||||
<label for="auto-reset">Reset on total extinction</label>
|
||||
<input type="checkbox" id="auto-reset" checked>
|
||||
<p id='reset-count'>Auto reset count: </p>
|
||||
<label for="auto-pause" title='Will override reset on extinction'>Pause on total extinction</label>
|
||||
<input type="checkbox" id="auto-pause">
|
||||
<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 class='right-half'>
|
||||
<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>
|
||||
<br>
|
||||
<label for="clear-walls-reset" title='When on, walls will be cleared when the environment resets'>Clear walls on reset</label>
|
||||
<input type="checkbox" id="clear-walls-reset">
|
||||
</div>
|
||||
</div>
|
||||
<div id='hyperparameters' class='tab'>
|
||||
<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>
|
||||
<input type="number" id="food-prod-prob" min=".001" max="100" value=4 step="1">
|
||||
<br>
|
||||
<label for="lifespan-multiplier" title='An organism lives for this many ticks per cell in its body.'>Lifespan multiplier:</label>
|
||||
<input type="number" id="lifespan-multiplier" min="1" max="10000" value=100 step="1">
|
||||
<br>
|
||||
<label for="mover-rot" title='Movers rotate randomly when they change directions.'>Movers can rotate</label>
|
||||
<input type="checkbox" id="mover-rot" checked>
|
||||
<br>
|
||||
<label for="offspring-rot" title='Offspring will randomly rotate'>Offspring rotate</label>
|
||||
<input type="checkbox" id="offspring-rot" checked>
|
||||
<label for="rot-enabled" title='Organisms rotate when born and while moving.'>Rotation Enabled</label>
|
||||
<input type="checkbox" id="rot-enabled" checked>
|
||||
<br>
|
||||
<label for="insta-kill" title='When on, killer cells immediatly kill organisms they touch. When off, organisms have as much health as they have cells and only take 1 damage from killer cells.'>One touch kill</label>
|
||||
<input type="checkbox" id="insta-kill">
|
||||
@@ -198,6 +209,9 @@
|
||||
<br>
|
||||
<label for="food-drop-rate" title='Rate at which food is automatically generated and dropped in the world'>Auto food drop rate:</label>
|
||||
<input type="number" id="food-drop-rate" value=0 max="1000">
|
||||
<br>
|
||||
<label for="extra-mover-cost" title='Additional food cost for movers to reproduce'>Extra mover reproduction cost:</label>
|
||||
<input type="number" id="extra-mover-cost" value=0 max="1000" step="1">
|
||||
|
||||
</div>
|
||||
<div class='right-half'>
|
||||
@@ -221,7 +235,10 @@
|
||||
<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>
|
||||
<br>
|
||||
|
||||
<button id='save-controls' title="Save all Evolution Controls in a .json file">Save & Download</button>
|
||||
<button id='load-controls' title="Load saved Evolution Controls with a .json file">Load</button>
|
||||
<a id="download-el" style="display: none;"></a>
|
||||
<input id="upload-el" style="display: none;" type="file">
|
||||
</div>
|
||||
</div>
|
||||
<div id='stats' class='tab'>
|
||||
@@ -246,22 +263,6 @@
|
||||
</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 class='hot-controls'>
|
||||
|
||||
@@ -6,7 +6,7 @@ const Modes = {
|
||||
Select: 4,
|
||||
Edit: 5,
|
||||
Clone: 6,
|
||||
Drag: 7
|
||||
Drag: 7,
|
||||
}
|
||||
|
||||
module.exports = Modes;
|
||||
@@ -1,6 +1,8 @@
|
||||
const Hyperparams = require("../Hyperparameters");
|
||||
const Modes = require("./ControlModes");
|
||||
const StatsPanel = require("../Stats/StatsPanel");
|
||||
const RandomOrganismGenerator = require("../Organism/RandomOrganismGenerator")
|
||||
const WorldConfig = require("../WorldConfig");
|
||||
|
||||
class ControlPanel {
|
||||
constructor(engine) {
|
||||
@@ -8,11 +10,10 @@ class ControlPanel {
|
||||
this.defineMinMaxControls();
|
||||
this.defineHotkeys();
|
||||
this.defineEngineSpeedControls();
|
||||
this.defineGridSizeControls();
|
||||
this.defineTabNavigation();
|
||||
this.defineHyperparameterControls();
|
||||
this.defineWorldControls();
|
||||
this.defineModeControls();
|
||||
this.defineChallenges();
|
||||
this.fps = engine.fps;
|
||||
this.organism_record=0;
|
||||
this.env_controller = this.engine.env.controller;
|
||||
@@ -114,38 +115,57 @@ class ControlPanel {
|
||||
defineEngineSpeedControls(){
|
||||
this.slider = document.getElementById("slider");
|
||||
this.slider.oninput = function() {
|
||||
this.fps = this.slider.value
|
||||
const max_fps = 300;
|
||||
this.fps = this.slider.value;
|
||||
if (this.fps>=max_fps) this.fps = 1000;
|
||||
if (this.engine.running) {
|
||||
this.changeEngineSpeed(this.fps);
|
||||
}
|
||||
$('#fps').text("Target FPS: "+this.fps);
|
||||
let text = this.fps >= max_fps ? 'MAX' : this.fps;
|
||||
$('#fps').text("Target FPS: "+text);
|
||||
}.bind(this);
|
||||
|
||||
$('.pause-button').click(function() {
|
||||
$('.pause-button').find("i").toggleClass("fa fa-pause");
|
||||
$('.pause-button').find("i").toggleClass("fa fa-play");
|
||||
this.paused = !this.paused;
|
||||
if (this.engine.running) {
|
||||
this.engine.stop();
|
||||
}
|
||||
else if (!this.engine.running){
|
||||
this.engine.start(this.fps);
|
||||
}
|
||||
// toggle pause
|
||||
this.setPaused(this.engine.running);
|
||||
}.bind(this));
|
||||
|
||||
$('.headless').click(function() {
|
||||
$('.headless').find("i").toggleClass("fa fa-eye");
|
||||
$('.headless').find("i").toggleClass("fa fa-eye-slash");
|
||||
if (Hyperparams.headless){
|
||||
if (WorldConfig.headless){
|
||||
$('#headless-notification').css('display', 'none');
|
||||
this.engine.env.renderFull();
|
||||
}
|
||||
else {
|
||||
$('#headless-notification').css('display', 'block');
|
||||
}
|
||||
Hyperparams.headless = !Hyperparams.headless;
|
||||
WorldConfig.headless = !WorldConfig.headless;
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
defineGridSizeControls() {
|
||||
defineTabNavigation() {
|
||||
this.tab_id = 'about';
|
||||
var self = this;
|
||||
$('.tabnav-item').click(function() {
|
||||
$('.tab').css('display', 'none');
|
||||
var tab = '#'+this.id+'.tab';
|
||||
$(tab).css('display', 'grid');
|
||||
$('.tabnav-item').removeClass('open-tab')
|
||||
$('#'+this.id+'.tabnav-item').addClass('open-tab');
|
||||
self.engine.organism_editor.is_active = (this.id == 'editor');
|
||||
self.stats_panel.stopAutoRender();
|
||||
if (this.id === 'stats') {
|
||||
self.stats_panel.startAutoRender();
|
||||
}
|
||||
else if (this.id === 'editor') {
|
||||
self.editor_controller.refreshDetailsPanel();
|
||||
}
|
||||
self.tab_id = this.id;
|
||||
});
|
||||
}
|
||||
|
||||
defineWorldControls() {
|
||||
$('#fill-window').change(function() {
|
||||
if (this.checked)
|
||||
$('.col-row-input').css('display' ,'none');
|
||||
@@ -168,24 +188,23 @@ class ControlPanel {
|
||||
this.stats_panel.reset();
|
||||
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
defineTabNavigation() {
|
||||
this.tab_id = 'about';
|
||||
var self = this;
|
||||
$('.tabnav-item').click(function() {
|
||||
$('.tab').css('display', 'none');
|
||||
var tab = '#'+this.id+'.tab';
|
||||
$(tab).css('display', 'grid');
|
||||
self.engine.organism_editor.is_active = (this.id == 'editor');
|
||||
self.stats_panel.stopAutoRender();
|
||||
if (this.id === 'stats') {
|
||||
self.stats_panel.startAutoRender();
|
||||
}
|
||||
else if (this.id === 'editor') {
|
||||
self.editor_controller.refreshDetailsPanel();
|
||||
}
|
||||
self.tab_id = this.id;
|
||||
$('#auto-reset').change(function() {
|
||||
WorldConfig.auto_reset = this.checked;
|
||||
});
|
||||
$('#auto-pause').change(function() {
|
||||
WorldConfig.auto_pause = this.checked;
|
||||
});
|
||||
$('#clear-walls-reset').change(function() {
|
||||
WorldConfig.clear_walls_on_reset = this.checked;
|
||||
});
|
||||
$('#reset-with-editor-org').click( () => {
|
||||
let env = this.engine.env;
|
||||
if (!env.reset(true, false)) return;
|
||||
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])
|
||||
});
|
||||
}
|
||||
|
||||
@@ -197,11 +216,8 @@ class ControlPanel {
|
||||
Hyperparams.lifespanMultiplier = $('#lifespan-multiplier').val();
|
||||
}.bind(this));
|
||||
|
||||
$('#mover-rot').change(function() {
|
||||
Hyperparams.moversCanRotate = this.checked;
|
||||
});
|
||||
$('#offspring-rot').change(function() {
|
||||
Hyperparams.offspringRotate = this.checked;
|
||||
$('#rot-enabled').change(function() {
|
||||
Hyperparams.rotationEnabled = this.checked;
|
||||
});
|
||||
$('#insta-kill').change(function() {
|
||||
Hyperparams.instaKill = this.checked;
|
||||
@@ -212,6 +228,9 @@ class ControlPanel {
|
||||
$('#food-drop-rate').change(function() {
|
||||
Hyperparams.foodDropProb = $('#food-drop-rate').val();
|
||||
});
|
||||
$('#extra-mover-cost').change(function() {
|
||||
Hyperparams.extraMoverFoodCost = parseInt($('#extra-mover-cost').val());
|
||||
});
|
||||
|
||||
$('#evolved-mutation').change( function() {
|
||||
if (this.checked) {
|
||||
@@ -252,14 +271,40 @@ class ControlPanel {
|
||||
$('#reset-rules').click(() => {
|
||||
this.setHyperparamDefaults();
|
||||
});
|
||||
$('#save-controls').click(() => {
|
||||
let data = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(Hyperparams));
|
||||
let downloadEl = document.getElementById('download-el');
|
||||
downloadEl.setAttribute("href", data);
|
||||
downloadEl.setAttribute("download", "controls.json");
|
||||
downloadEl.click();
|
||||
});
|
||||
$('#load-controls').click(() => {
|
||||
$('#upload-el').click();
|
||||
});
|
||||
$('#upload-el').change((e)=>{
|
||||
let files = e.target.files;
|
||||
if (!files.length) {return;};
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
let result=JSON.parse(e.target.result);
|
||||
Hyperparams.loadJsonObj(result);
|
||||
this.updateHyperparamUIValues();
|
||||
// have to clear the value so change() will be triggered if the same file is uploaded again
|
||||
$('#upload-el')[0].value = '';
|
||||
};
|
||||
reader.readAsText(files[0]);
|
||||
});
|
||||
}
|
||||
|
||||
setHyperparamDefaults() {
|
||||
Hyperparams.setDefaults();
|
||||
this.updateHyperparamUIValues();
|
||||
}
|
||||
|
||||
updateHyperparamUIValues(){
|
||||
$('#food-prod-prob').val(Hyperparams.foodProdProb);
|
||||
$('#lifespan-multiplier').val(Hyperparams.lifespanMultiplier);
|
||||
$('#mover-rot').prop('checked', Hyperparams.moversCanRotate);
|
||||
$('#offspring-rot').prop('checked', Hyperparams.offspringRotate);
|
||||
$('#rot-enabled').prop('checked', Hyperparams.rotationEnabled);
|
||||
$('#insta-kill').prop('checked', Hyperparams.instaKill);
|
||||
$('#evolved-mutation').prop('checked', !Hyperparams.useGlobalMutability);
|
||||
$('#add-prob').val(Hyperparams.addProb);
|
||||
@@ -268,6 +313,7 @@ class ControlPanel {
|
||||
$('#movers-produce').prop('checked', Hyperparams.moversCanProduce);
|
||||
$('#food-blocks').prop('checked', Hyperparams.foodBlocksReproduction);
|
||||
$('#food-drop-rate').val(Hyperparams.foodDropProb);
|
||||
$('#extra-mover-cost').val(Hyperparams.extraMoverFoodCost);
|
||||
$('#look-range').val(Hyperparams.lookRange);
|
||||
|
||||
if (!Hyperparams.useGlobalMutability) {
|
||||
@@ -311,7 +357,6 @@ class ControlPanel {
|
||||
$('.edit-mode-btn').removeClass('selected');
|
||||
$('.'+this.id).addClass('selected');
|
||||
});
|
||||
|
||||
$('.reset-view').click( function(){
|
||||
this.env_controller.resetView();
|
||||
}.bind(this));
|
||||
@@ -324,19 +369,24 @@ class ControlPanel {
|
||||
$('#clear-env').click( () => {
|
||||
env.reset(true, false);
|
||||
this.stats_panel.reset();
|
||||
env.auto_reset = false;
|
||||
$('#auto-reset').prop('checked', false);;
|
||||
});
|
||||
$('#auto-reset').change(function() {
|
||||
env.auto_reset = this.checked;
|
||||
});
|
||||
$('#random-walls').click( function() {
|
||||
this.env_controller.randomizeWalls();
|
||||
}.bind(this));
|
||||
$('#clear-walls').click( function() {
|
||||
this.engine.env.clearWalls();
|
||||
}.bind(this));
|
||||
$('#clear-editor').click( function() {
|
||||
this.engine.organism_editor.clear();
|
||||
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) {
|
||||
e = e || window.event;
|
||||
@@ -348,11 +398,22 @@ class ControlPanel {
|
||||
};
|
||||
}
|
||||
|
||||
defineChallenges() {
|
||||
$('.challenge-btn').click(function() {
|
||||
$('#challenge-title').text($(this).text());
|
||||
$('#challenge-description').text($(this).val());
|
||||
});
|
||||
setPaused(paused) {
|
||||
|
||||
if (paused) {
|
||||
|
||||
$('.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) {
|
||||
@@ -383,7 +444,7 @@ class ControlPanel {
|
||||
}
|
||||
|
||||
updateHeadlessIcon(delta_time) {
|
||||
if (this.paused)
|
||||
if (!this.engine.running)
|
||||
return;
|
||||
const min_opacity = 0.4;
|
||||
var op = this.headless_opacity + (this.opacity_change_rate*delta_time/1000);
|
||||
@@ -403,7 +464,7 @@ class ControlPanel {
|
||||
$('#fps-actual').text("Actual FPS: " + Math.floor(this.engine.actual_fps));
|
||||
$('#reset-count').text("Auto reset count: " + this.engine.env.reset_count);
|
||||
this.stats_panel.updateDetails();
|
||||
if (Hyperparams.headless)
|
||||
if (WorldConfig.headless)
|
||||
this.updateHeadlessIcon(delta_time);
|
||||
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ class EditorController extends CanvasController{
|
||||
clearDetailsPanel() {
|
||||
$('#organism-details').css('display', 'none');
|
||||
$('#edit-organism-details').css('display', 'none');
|
||||
$('#randomize-organism-details').css('display', 'none');
|
||||
}
|
||||
|
||||
refreshDetailsPanel() {
|
||||
@@ -213,6 +214,11 @@ class EditorController extends CanvasController{
|
||||
var reaction = this.env.organism.brain.decisions[name];
|
||||
$('#reaction-edit').val(reaction);
|
||||
}
|
||||
|
||||
setRandomizePanel() {
|
||||
this.clearDetailsPanel();
|
||||
$('#randomize-organism-details').css('display', 'block');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EditorController;
|
||||
|
||||
@@ -4,7 +4,8 @@ const Modes = require("./ControlModes");
|
||||
const CellStates = require("../Organism/Cell/CellStates");
|
||||
const Neighbors = require("../Grid/Neighbors");
|
||||
const FossilRecord = require("../Stats/FossilRecord");
|
||||
const Hyperparams = require("../Hyperparameters");
|
||||
const WorldConfig = require("../WorldConfig");
|
||||
const Perlin = require("../Utils/Perlin");
|
||||
|
||||
class EnvironmentController extends CanvasController{
|
||||
constructor(env, canvas) {
|
||||
@@ -51,8 +52,34 @@ class EnvironmentController extends CanvasController{
|
||||
this.scale = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Iterate over grid from 0,0 to env.num_cols,env.num_rows and create random walls using perlin noise to create a more organic shape.
|
||||
*/
|
||||
randomizeWalls(thickness=1) {
|
||||
this.env.clearWalls();
|
||||
const noise_threshold = -0.017;
|
||||
let avg_noise = 0;
|
||||
let resolution = 20;
|
||||
Perlin.seed();
|
||||
|
||||
for (let r = 0; r < this.env.num_rows; r++) {
|
||||
for (let c = 0; c < this.env.num_cols; c++) {
|
||||
let xval = c/this.env.num_cols*(resolution/this.env.renderer.cell_size*(this.env.num_cols/this.env.num_rows));
|
||||
let yval = r/this.env.num_rows*(resolution/this.env.renderer.cell_size*(this.env.num_rows/this.env.num_cols));
|
||||
let noise = Perlin.get(xval, yval);
|
||||
avg_noise += noise/(this.env.num_rows*this.env.num_cols);
|
||||
if (noise > noise_threshold && noise < noise_threshold + thickness/resolution) {
|
||||
let cell = this.env.grid_map.cellAt(c, r);
|
||||
if (cell != null) {
|
||||
if(cell.owner != null) cell.owner.die();
|
||||
this.env.changeCell(c, r, CellStates.wall, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateMouseLocation(offsetX, offsetY){
|
||||
|
||||
super.updateMouseLocation(offsetX, offsetY);
|
||||
}
|
||||
|
||||
@@ -71,7 +98,7 @@ class EnvironmentController extends CanvasController{
|
||||
}
|
||||
|
||||
performModeAction() {
|
||||
if (Hyperparams.headless)
|
||||
if (WorldConfig.headless && this.mode != Modes.Drag)
|
||||
return;
|
||||
var mode = this.mode;
|
||||
var right_click = this.right_click;
|
||||
@@ -114,21 +141,7 @@ class EnvironmentController extends CanvasController{
|
||||
|
||||
case Modes.Clone:
|
||||
if (this.org_to_clone != null){
|
||||
var new_org = new Organism(this.mouse_c, this.mouse_r, this.env, this.org_to_clone);
|
||||
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();
|
||||
}
|
||||
this.dropOrganism(this.org_to_clone, this.mouse_c, this.mouse_r);
|
||||
}
|
||||
break;
|
||||
case Modes.Drag:
|
||||
@@ -152,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) {
|
||||
for (var loc of Neighbors.allSelf){
|
||||
var c=col + loc[0];
|
||||
|
||||
@@ -5,6 +5,7 @@ const Renderer = require('../Rendering/Renderer');
|
||||
const CellStates = require('../Organism/Cell/CellStates');
|
||||
const EditorController = require("../Controllers/EditorController");
|
||||
const Species = require('../Stats/Species');
|
||||
const RandomOrganismGenerator = require('../Organism/RandomOrganismGenerator')
|
||||
|
||||
class OrganismEditor extends Environment{
|
||||
constructor() {
|
||||
@@ -87,6 +88,31 @@ class OrganismEditor extends Environment{
|
||||
this.organism.updateGrid();
|
||||
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;
|
||||
@@ -6,19 +6,19 @@ const CellStates = require('../Organism/Cell/CellStates');
|
||||
const EnvironmentController = require('../Controllers/EnvironmentController');
|
||||
const Hyperparams = require('../Hyperparameters.js');
|
||||
const FossilRecord = require('../Stats/FossilRecord');
|
||||
const WorldConfig = require('../WorldConfig');
|
||||
|
||||
class WorldEnvironment extends Environment{
|
||||
constructor(cell_size) {
|
||||
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.num_rows = Math.ceil(this.renderer.height / cell_size);
|
||||
this.num_cols = Math.ceil(this.renderer.width / cell_size);
|
||||
this.grid_map = new GridMap(this.num_cols, this.num_rows, cell_size);
|
||||
this.organisms = [];
|
||||
this.walls = [];
|
||||
this.total_mutability = 0;
|
||||
this.auto_reset = true;
|
||||
this.largest_cell_count = 0;
|
||||
this.reset_count = 0;
|
||||
this.total_ticks = 0;
|
||||
@@ -45,7 +45,7 @@ class WorldEnvironment extends Environment{
|
||||
}
|
||||
|
||||
render() {
|
||||
if (Hyperparams.headless) {
|
||||
if (WorldConfig.headless) {
|
||||
this.renderer.cells_to_render.clear();
|
||||
return;
|
||||
}
|
||||
@@ -58,13 +58,18 @@ class WorldEnvironment extends Environment{
|
||||
}
|
||||
|
||||
removeOrganisms(org_indeces) {
|
||||
let start_pop = this.organisms.length;
|
||||
for (var i of org_indeces.reverse()){
|
||||
this.total_mutability -= this.organisms[i].mutability;
|
||||
this.organisms.splice(i, 1);
|
||||
}
|
||||
if (this.organisms.length == 0 && this.auto_reset){
|
||||
this.reset_count++;
|
||||
this.reset(false);
|
||||
if (this.organisms.length === 0 && start_pop > 0) {
|
||||
if (WorldConfig.auto_pause)
|
||||
$('.pause-button')[0].click();
|
||||
else if(WorldConfig.auto_reset) {
|
||||
this.reset_count++;
|
||||
this.reset(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +109,8 @@ class WorldEnvironment extends Environment{
|
||||
|
||||
clearWalls() {
|
||||
for(var wall of this.walls){
|
||||
if (this.grid_map.cellAt(wall.col, wall.row).state == CellStates.wall)
|
||||
let wcell = this.grid_map.cellAt(wall.col, wall.row);
|
||||
if (wcell && wcell.state == CellStates.wall)
|
||||
this.changeCell(wall.col, wall.row, CellStates.empty, null);
|
||||
}
|
||||
}
|
||||
@@ -132,17 +138,17 @@ class WorldEnvironment extends Environment{
|
||||
|
||||
reset(confirm_reset=true, reset_life=true) {
|
||||
if (confirm_reset && !confirm('The current environment will be lost. Proceed?'))
|
||||
return;
|
||||
return false;
|
||||
|
||||
this.organisms = [];
|
||||
this.grid_map.fillGrid(CellStates.empty);
|
||||
this.grid_map.fillGrid(CellStates.empty, !WorldConfig.clear_walls_on_reset);
|
||||
this.renderer.renderFullGrid(this.grid_map.grid);
|
||||
this.total_mutability = 0;
|
||||
this.total_ticks = 0;
|
||||
FossilRecord.clear_record();
|
||||
if (reset_life)
|
||||
this.OriginOfLife();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
resizeGridColRow(cell_size, cols, rows) {
|
||||
@@ -154,9 +160,9 @@ class WorldEnvironment extends Environment{
|
||||
resizeFillWindow(cell_size) {
|
||||
this.renderer.cell_size = cell_size;
|
||||
this.renderer.fillWindow('env');
|
||||
var cols = Math.ceil(this.renderer.width / cell_size);
|
||||
var rows = Math.ceil(this.renderer.height / cell_size);
|
||||
this.grid_map.resize(cols, rows, cell_size);
|
||||
this.num_cols = Math.ceil(this.renderer.width / cell_size);
|
||||
this.num_rows = Math.ceil(this.renderer.height / cell_size);
|
||||
this.grid_map.resize(this.num_cols, this.num_rows, cell_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,10 @@ class GridMap {
|
||||
}
|
||||
}
|
||||
|
||||
fillGrid(state) {
|
||||
fillGrid(state, ignore_walls=false) {
|
||||
for (var col of this.grid) {
|
||||
for (var cell of col) {
|
||||
if (ignore_walls && cell.state===CellStates.wall) continue;
|
||||
cell.setType(state);
|
||||
cell.owner = null;
|
||||
cell.cell_owner = null;
|
||||
|
||||
@@ -2,8 +2,6 @@ const Neighbors = require("./Grid/Neighbors");
|
||||
|
||||
const Hyperparams = {
|
||||
setDefaults: function() {
|
||||
this.headless = false;
|
||||
|
||||
this.lifespanMultiplier = 100;
|
||||
this.foodProdProb = 5;
|
||||
this.killableNeighbors = Neighbors.adjacent;
|
||||
@@ -16,8 +14,7 @@ const Hyperparams = {
|
||||
this.changeProb = 33;
|
||||
this.removeProb = 33;
|
||||
|
||||
this.moversCanRotate = true;
|
||||
this.offspringRotate = true;
|
||||
this.rotationEnabled = true;
|
||||
|
||||
this.foodBlocksReproduction = true;
|
||||
this.moversCanProduce = false;
|
||||
@@ -27,7 +24,15 @@ const Hyperparams = {
|
||||
this.lookRange = 20;
|
||||
|
||||
this.foodDropProb = 0;
|
||||
|
||||
this.extraMoverFoodCost = 0;
|
||||
},
|
||||
|
||||
loadJsonObj(obj) {
|
||||
for (let key in obj) {
|
||||
this[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Hyperparams.setDefaults();
|
||||
|
||||
@@ -91,6 +91,22 @@ class Anatomy {
|
||||
getRandomCell() {
|
||||
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;
|
||||
@@ -95,6 +95,7 @@ const CellStates = {
|
||||
return this.living[Math.floor(Math.random() * this.living.length)];
|
||||
}
|
||||
}
|
||||
|
||||
CellStates.defineLists();
|
||||
|
||||
module.exports = CellStates;
|
||||
|
||||
@@ -5,7 +5,7 @@ const Hyperparams = require("../../Hyperparameters");
|
||||
class Cell{
|
||||
constructor(state, col, row, x, y){
|
||||
this.owner = null; // owner organism
|
||||
this.cell_owner = null; // owner cell of ^that organism
|
||||
this.cell_owner = null; // specific body cell of the owner organism that occupies this grid cell
|
||||
this.setType(state);
|
||||
this.col = col;
|
||||
this.row = row;
|
||||
|
||||
@@ -17,7 +17,7 @@ class Organism {
|
||||
this.anatomy = new Anatomy(this)
|
||||
this.direction = Directions.down; // direction of movement
|
||||
this.rotation = Directions.up; // direction of rotation
|
||||
this.can_rotate = Hyperparams.moversCanRotate;
|
||||
this.can_rotate = Hyperparams.rotationEnabled;
|
||||
this.move_count = 0;
|
||||
this.move_range = 4;
|
||||
this.ignore_brain_for = 0;
|
||||
@@ -47,11 +47,10 @@ class Organism {
|
||||
|
||||
// amount of food required before it can reproduce
|
||||
foodNeeded() {
|
||||
return this.anatomy.cells.length;
|
||||
return this.anatomy.is_mover ? this.anatomy.cells.length + Hyperparams.extraMoverFoodCost : this.anatomy.cells.length;
|
||||
}
|
||||
|
||||
lifespan() {
|
||||
// console.log(Hyperparams.lifespanMultiplier)
|
||||
return this.anatomy.cells.length * Hyperparams.lifespanMultiplier;
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ class Organism {
|
||||
//produce mutated child
|
||||
//check nearby locations (is there room and a direct path)
|
||||
var org = new Organism(0, 0, this.env, this);
|
||||
if(Hyperparams.offspringRotate){
|
||||
if(Hyperparams.rotationEnabled){
|
||||
org.rotation = Directions.getRandomDirection();
|
||||
}
|
||||
var prob = this.mutability;
|
||||
@@ -118,7 +117,7 @@ class Organism {
|
||||
org.species.addPop();
|
||||
}
|
||||
}
|
||||
this.food_collected -= this.foodNeeded();
|
||||
Math.max(this.food_collected -= this.foodNeeded(), 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -237,14 +236,13 @@ class Organism {
|
||||
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) {
|
||||
var cell = this.getRealCell(loccell, col, row, rotation);
|
||||
if (cell==null) {
|
||||
return false;
|
||||
}
|
||||
// console.log(cell.owner == this)
|
||||
if (cell.owner==this || cell.state==CellStates.empty || (!Hyperparams.foodBlocksReproduction && cell.state==CellStates.food) || (ignore_armor && loccell.state==CellStates.armor && cell.state==CellStates.food)){
|
||||
if (cell.owner==this || cell.state==CellStates.empty || (!Hyperparams.foodBlocksReproduction && cell.state==CellStates.food)){
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -32,8 +32,12 @@ class Brain {
|
||||
this.decisions[CellStates.eye.name] = Decision.neutral;
|
||||
}
|
||||
|
||||
randomizeDecisions() {
|
||||
randomizeDecisions(randomize_all=false) {
|
||||
// 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.producer.name] = Decision.getRandom();
|
||||
this.decisions[CellStates.mover.name] = Decision.getRandom();
|
||||
@@ -79,4 +83,6 @@ class Brain {
|
||||
}
|
||||
}
|
||||
|
||||
Brain.Decision = Decision;
|
||||
|
||||
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() {
|
||||
var r_len = FossilRecord.tick_record.length;
|
||||
var newest_t = -1;
|
||||
var oldest_t = 0;
|
||||
if (this.data[0].dataPoints.length>0) {
|
||||
newest_t = this.data[0].dataPoints[this.data[0].dataPoints.length-1].x;
|
||||
newest_t = this.data[0].dataPoints[0].x;
|
||||
let record_size = FossilRecord.tick_record.length;
|
||||
let data_points = this.data[0].dataPoints;
|
||||
let newest_t = -1;
|
||||
if (data_points.length>0) {
|
||||
newest_t = this.data[0].dataPoints[data_points.length-1].x;
|
||||
}
|
||||
if (newest_t < FossilRecord.tick_record[r_len-1]) {
|
||||
this.addNewest();
|
||||
let to_add = 0;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
addNewest() {
|
||||
var i = FossilRecord.tick_record.length-1;
|
||||
this.addDataPoint(i);
|
||||
}
|
||||
|
||||
addDataPoint(i) {
|
||||
alert("Must override addDataPoint")
|
||||
addNewest(to_add) {
|
||||
for (let i=to_add; i>0; i--) {
|
||||
let j = FossilRecord.tick_record.length-i;
|
||||
this.addDataPoint(j);
|
||||
}
|
||||
}
|
||||
|
||||
removeOldest() {
|
||||
@@ -75,6 +80,10 @@ class ChartController {
|
||||
}
|
||||
}
|
||||
|
||||
addDataPoint(i) {
|
||||
alert("Must override addDataPoint")
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.data.length = 0;
|
||||
this.chart.render();
|
||||
|
||||
@@ -82,8 +82,7 @@ const FossilRecord = {
|
||||
this.species_counts.push(this.extant_species.length);
|
||||
this.av_mut_rates.push(this.env.averageMutability());
|
||||
this.calcCellCountAverages();
|
||||
|
||||
if (this.tick_record.length > this.record_size_limit) {
|
||||
while (this.tick_record.length > this.record_size_limit) {
|
||||
this.tick_record.shift();
|
||||
this.pop_counts.shift();
|
||||
this.species_counts.shift();
|
||||
|
||||
46
src/Utils/Perlin.js
Normal file
46
src/Utils/Perlin.js
Normal file
@@ -0,0 +1,46 @@
|
||||
let perlin = {
|
||||
rand_vect: function(){
|
||||
let theta = Math.random() * 2 * Math.PI;
|
||||
return {x: Math.cos(theta), y: Math.sin(theta)};
|
||||
},
|
||||
dot_prod_grid: function(x, y, vx, vy){
|
||||
let g_vect;
|
||||
let d_vect = {x: x - vx, y: y - vy};
|
||||
if (this.gradients[[vx,vy]]){
|
||||
g_vect = this.gradients[[vx,vy]];
|
||||
} else {
|
||||
g_vect = this.rand_vect();
|
||||
this.gradients[[vx, vy]] = g_vect;
|
||||
}
|
||||
return d_vect.x * g_vect.x + d_vect.y * g_vect.y;
|
||||
},
|
||||
smootherstep: function(x){
|
||||
return 6*x**5 - 15*x**4 + 10*x**3;
|
||||
},
|
||||
interp: function(x, a, b){
|
||||
return a + this.smootherstep(x) * (b-a);
|
||||
},
|
||||
seed: function(){
|
||||
this.gradients = {};
|
||||
this.memory = {};
|
||||
},
|
||||
get: function(x, y) {
|
||||
if (this.memory.hasOwnProperty([x,y]))
|
||||
return this.memory[[x,y]];
|
||||
let xf = Math.floor(x);
|
||||
let yf = Math.floor(y);
|
||||
//interpolate
|
||||
let tl = this.dot_prod_grid(x, y, xf, yf);
|
||||
let tr = this.dot_prod_grid(x, y, xf+1, yf);
|
||||
let bl = this.dot_prod_grid(x, y, xf, yf+1);
|
||||
let br = this.dot_prod_grid(x, y, xf+1, yf+1);
|
||||
let xt = this.interp(x-xf, tl, tr);
|
||||
let xb = this.interp(x-xf, bl, br);
|
||||
let v = this.interp(y-yf, xt, xb);
|
||||
this.memory[[x,y]] = v;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
perlin.seed();
|
||||
|
||||
module.exports = perlin;
|
||||
8
src/WorldConfig.js
Normal file
8
src/WorldConfig.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const WorldConfig = {
|
||||
headless: false,
|
||||
clear_walls_on_reset: false,
|
||||
auto_reset: true,
|
||||
auto_pause: false,
|
||||
}
|
||||
|
||||
module.exports = WorldConfig;
|
||||
Reference in New Issue
Block a user