Merge pull request #64 from MaxRobinsonTheGreat/reset-improvements

Reset improvements
This commit is contained in:
Max Robinson
2021-12-04 00:04:14 -06:00
committed by GitHub
6 changed files with 70 additions and 47 deletions

4
dist/css/style.css vendored
View File

@@ -37,7 +37,7 @@ body{
bottom: 0;
position: fixed;
background-color: #3a4b68;
display: grid;
display: none;
grid-template-columns: repeat(3, 1fr);
/* opacity: 0.8; */
}
@@ -236,7 +236,7 @@ button:active{
position: fixed;
bottom: 10px;
padding-left: 10px;
display: none;
/* display: none; */
}
#headless-notification {

16
dist/index.html vendored
View File

@@ -20,9 +20,9 @@
<div id='speed-controller' class='control-set'>
<div class='vertical-buttons'>
<button class="reset-view" title="Reset View. Hotkey: A"><i class="fa fa-video-camera"></i></button>
<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 drag-view" 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 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>
@@ -32,12 +32,13 @@
<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'>Reset Environment</button>
<label for="auto-reset">Auto Reset</label>
<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>
<br>
<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">
@@ -46,7 +47,6 @@
<div class='col-row-input'>
<label for="col-input">Columns:</label>
<input type="number" id="col-input" min="1" value=100 step="1">
<br>
<label for="row-input">Rows:</label>
<input type="number" id="row-input" min="1" value=100 step="1">
</div>
@@ -266,9 +266,9 @@
</div>
<div class='hot-controls'>
<button class="reset-view" title="Reset View. Hotkey: A"><i class="fa fa-video-camera"></i></button>
<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 drag-view" 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 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 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>

View File

@@ -23,6 +23,7 @@ class ControlPanel {
this.headless_opacity = 1;
this.opacity_change_rate = -0.8;
this.paused=false;
this.setHyperparamDefaults();
}
defineMinMaxControls(){
@@ -248,33 +249,37 @@ class ControlPanel {
$('#food-blocks').change( function() {
Hyperparams.foodBlocksReproduction = this.checked;
});
$('#reset-rules').click( function() {
Hyperparams.setDefaults();
$('#food-prod-prob').val(Hyperparams.foodProdProb);
$('#lifespan-multiplier').val(Hyperparams.lifespanMultiplier);
$('#mover-rot').prop('checked', Hyperparams.moversCanRotate);
$('#offspring-rot').prop('checked', Hyperparams.offspringRotate);
$('#insta-kill').prop('checked', Hyperparams.instaKill);
$('#evolved-mutation').prop('checked', !Hyperparams.useGlobalMutability);
$('#add-prob').val(Hyperparams.addProb);
$('#change-prob').val(Hyperparams.changeProb);
$('#remove-prob').val(Hyperparams.removeProb);
$('#movers-produce').prop('checked', Hyperparams.moversCanProduce);
$('#food-blocks').prop('checked', Hyperparams.foodBlocksReproduction);
$('#food-drop-rate').val(Hyperparams.foodDropProb);
$('#look-range').val(Hyperparams.lookRange);
if (!Hyperparams.useGlobalMutability) {
$('.global-mutation-in').css('display', 'none');
$('#avg-mut').css('display', 'block');
}
else {
$('.global-mutation-in').css('display', 'block');
$('#avg-mut').css('display', 'none');
}
$('#reset-rules').click(() => {
this.setHyperparamDefaults();
});
}
setHyperparamDefaults() {
Hyperparams.setDefaults();
$('#food-prod-prob').val(Hyperparams.foodProdProb);
$('#lifespan-multiplier').val(Hyperparams.lifespanMultiplier);
$('#mover-rot').prop('checked', Hyperparams.moversCanRotate);
$('#offspring-rot').prop('checked', Hyperparams.offspringRotate);
$('#insta-kill').prop('checked', Hyperparams.instaKill);
$('#evolved-mutation').prop('checked', !Hyperparams.useGlobalMutability);
$('#add-prob').val(Hyperparams.addProb);
$('#change-prob').val(Hyperparams.changeProb);
$('#remove-prob').val(Hyperparams.removeProb);
$('#movers-produce').prop('checked', Hyperparams.moversCanProduce);
$('#food-blocks').prop('checked', Hyperparams.foodBlocksReproduction);
$('#food-drop-rate').val(Hyperparams.foodDropProb);
$('#look-range').val(Hyperparams.lookRange);
if (!Hyperparams.useGlobalMutability) {
$('.global-mutation-in').css('display', 'none');
$('#avg-mut').css('display', 'block');
}
else {
$('.global-mutation-in').css('display', 'block');
$('#avg-mut').css('display', 'none');
}
}
defineModeControls() {
var self = this;
$('.edit-mode-btn').click( function() {
@@ -313,21 +318,34 @@ class ControlPanel {
var env = this.engine.env;
$('#reset-env').click( function() {
this.engine.env.reset();
env.reset();
this.stats_panel.reset();
}.bind(this));
$('#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;
});
$('#clear-walls').click( function() {
if (confirm("Are you sure you want to clear all the walls?")) {
this.engine.env.clearWalls();
}
this.engine.env.clearWalls();
}.bind(this));
$('#clear-editor').click( function() {
this.engine.organism_editor.clear();
this.editor_controller.setEditorPanel();
}.bind(this));
}.bind(this))
window.onbeforeunload = function (e) {
e = e || window.event;
let return_str = 'this will cause a confirmation on page close'
if (e) {
e.returnValue = return_str;
}
return return_str;
};
}
defineChallenges() {
@@ -367,9 +385,10 @@ class ControlPanel {
updateHeadlessIcon(delta_time) {
if (this.paused)
return;
const min_opacity = 0.4;
var op = this.headless_opacity + (this.opacity_change_rate*delta_time/1000);
if (op <= 0.4){
op=0.4;
if (op <= min_opacity){
op=min_opacity;
this.opacity_change_rate = -this.opacity_change_rate;
}
else if (op >= 1){

View File

@@ -9,7 +9,7 @@ const Hyperparams = require("../Hyperparameters");
class EnvironmentController extends CanvasController{
constructor(env, canvas) {
super(env, canvas);
this.mode = Modes.Drag;
this.mode = Modes.FoodDrop;
this.org_to_clone = null;
this.add_new_species = false;
this.defineZoomControls();

View File

@@ -64,7 +64,7 @@ class WorldEnvironment extends Environment{
}
if (this.organisms.length == 0 && this.auto_reset){
this.reset_count++;
this.reset();
this.reset(false);
}
}
@@ -130,14 +130,19 @@ class WorldEnvironment extends Environment{
}
}
reset() {
reset(confirm_reset=true, reset_life=true) {
if (confirm_reset && !confirm('The current environment will be lost. Proceed?'))
return;
this.organisms = [];
this.grid_map.fillGrid(CellStates.empty);
this.renderer.renderFullGrid(this.grid_map.grid);
this.total_mutability = 0;
this.total_ticks = 0;
FossilRecord.clear_record();
this.OriginOfLife();
if (reset_life)
this.OriginOfLife();
}
resizeGridColRow(cell_size, cols, rows) {

View File

@@ -5,8 +5,7 @@ const Hyperparams = {
this.headless = false;
this.lifespanMultiplier = 100;
this.foodProdProb = 4;
this.foodProdProbScalar = 4;
this.foodProdProb = 5;
this.killableNeighbors = Neighbors.adjacent;
this.edibleNeighbors = Neighbors.adjacent;
this.growableNeighbors = Neighbors.adjacent;