world config + improved wall clearing

This commit is contained in:
MaxRobinsonTheGreat
2021-12-18 11:53:30 -06:00
parent fe2d6aae7c
commit c319ed9dc5
7 changed files with 24 additions and 16 deletions

13
dist/index.html vendored
View File

@@ -51,7 +51,7 @@
<div id='about' class='tab'> <div id='about' class='tab'>
<div class='left-half'> <div class='left-half'>
<h3>The Life Engine</h3> <h3>The Life Engine</h3>
<p>The Life Engine is a virtual ecosystem that allows organisms to grow, spread, and compete.</p> <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> <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 id='cell-legend'>
<div class='cell-legend-type' id='mouth' title="Mouth: Eats adjacent food."></div> <div class='cell-legend-type' id='mouth' title="Mouth: Eats adjacent food."></div>
@@ -169,17 +169,16 @@
<br> <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="auto-reset">Reset on total extinction</label>
<input type="checkbox" id="auto-reset" checked>
<br>
<p id='reset-count'>Auto reset count: </p>
<label for="reset-options">Starting state:</label> <label for="reset-options">Starting state:</label>
<select name="reset-options" id="reset-options"> <select name="reset-options" id="reset-options">
<option value="default-org">Simple producer</option> <option value="default-org">Simple producer</option>
<option value="rand-orgs">Random organisms</option> <option value="rand-orgs">Random organisms</option>
<option value="empty">No organisms</option> <option value="empty">No organisms</option>
</select> </select> <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>
</div> </div>
<div class='right-half'> <div class='right-half'>
<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>

View File

@@ -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 WorldConfig = require("../WorldConfig");
class ControlPanel { class ControlPanel {
constructor(engine) { constructor(engine) {
@@ -137,14 +138,14 @@ class ControlPanel {
$('.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");
if (Hyperparams.headless){ if (WorldConfig.headless){
$('#headless-notification').css('display', 'none'); $('#headless-notification').css('display', 'none');
this.engine.env.renderFull(); this.engine.env.renderFull();
} }
else { else {
$('#headless-notification').css('display', 'block'); $('#headless-notification').css('display', 'block');
} }
Hyperparams.headless = !Hyperparams.headless; WorldConfig.headless = !WorldConfig.headless;
}.bind(this)); }.bind(this));
} }
@@ -411,7 +412,7 @@ class ControlPanel {
$('#fps-actual').text("Actual FPS: " + Math.floor(this.engine.actual_fps)); $('#fps-actual').text("Actual FPS: " + Math.floor(this.engine.actual_fps));
$('#reset-count').text("Auto reset count: " + this.engine.env.reset_count); $('#reset-count').text("Auto reset count: " + this.engine.env.reset_count);
this.stats_panel.updateDetails(); this.stats_panel.updateDetails();
if (Hyperparams.headless) if (WorldConfig.headless)
this.updateHeadlessIcon(delta_time); this.updateHeadlessIcon(delta_time);
} }

View File

@@ -4,7 +4,7 @@ const Modes = require("./ControlModes");
const CellStates = require("../Organism/Cell/CellStates"); const CellStates = require("../Organism/Cell/CellStates");
const Neighbors = require("../Grid/Neighbors"); const Neighbors = require("../Grid/Neighbors");
const FossilRecord = require("../Stats/FossilRecord"); const FossilRecord = require("../Stats/FossilRecord");
const Hyperparams = require("../Hyperparameters"); const WorldConfig = require("../WorldConfig");
const Perlin = require("../Utils/Perlin"); const Perlin = require("../Utils/Perlin");
class EnvironmentController extends CanvasController{ class EnvironmentController extends CanvasController{
@@ -98,7 +98,7 @@ class EnvironmentController extends CanvasController{
} }
performModeAction() { performModeAction() {
if (Hyperparams.headless && this.mode != Modes.Drag) if (WorldConfig.headless && this.mode != Modes.Drag)
return; return;
var mode = this.mode; var mode = this.mode;
var right_click = this.right_click; var right_click = this.right_click;

View File

@@ -6,6 +6,7 @@ const CellStates = require('../Organism/Cell/CellStates');
const EnvironmentController = require('../Controllers/EnvironmentController'); const EnvironmentController = require('../Controllers/EnvironmentController');
const Hyperparams = require('../Hyperparameters.js'); const Hyperparams = require('../Hyperparameters.js');
const FossilRecord = require('../Stats/FossilRecord'); const FossilRecord = require('../Stats/FossilRecord');
const WorldConfig = require('../WorldConfig');
class WorldEnvironment extends Environment{ class WorldEnvironment extends Environment{
constructor(cell_size) { constructor(cell_size) {
@@ -45,7 +46,7 @@ class WorldEnvironment extends Environment{
} }
render() { render() {
if (Hyperparams.headless) { if (WorldConfig.headless) {
this.renderer.cells_to_render.clear(); this.renderer.cells_to_render.clear();
return; return;
} }
@@ -136,7 +137,7 @@ class WorldEnvironment extends Environment{
return; return;
this.organisms = []; 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.renderer.renderFullGrid(this.grid_map.grid);
this.total_mutability = 0; this.total_mutability = 0;
this.total_ticks = 0; this.total_ticks = 0;

View File

@@ -21,9 +21,10 @@ class GridMap {
} }
} }
fillGrid(state) { fillGrid(state, ignore_walls=false) {
for (var col of this.grid) { for (var col of this.grid) {
for (var cell of col) { for (var cell of col) {
if (ignore_walls && cell.state===CellStates.wall) continue;
cell.setType(state); cell.setType(state);
cell.owner = null; cell.owner = null;
cell.cell_owner = null; cell.cell_owner = null;

View File

@@ -5,7 +5,7 @@ const Hyperparams = require("../../Hyperparameters");
class Cell{ class Cell{
constructor(state, col, row, x, y){ constructor(state, col, row, x, y){
this.owner = null; // owner organism 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.setType(state);
this.col = col; this.col = col;
this.row = row; this.row = row;

6
src/WorldConfig.js Normal file
View File

@@ -0,0 +1,6 @@
const WorldConfig = {
headless: false,
clear_walls_on_reset: false,
}
module.exports = WorldConfig;