basic start state and auto reset/pause

This commit is contained in:
MaxRobinsonTheGreat
2021-12-18 13:22:52 -06:00
parent adc826d6a6
commit f6db669adb
4 changed files with 39 additions and 18 deletions

View File

@@ -195,12 +195,18 @@ class ControlPanel {
}.bind(this));
$('#auto-reset').change(function() {
env.auto_reset = this.checked;
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;
})
$('#start-state').change ( function() {
WorldConfig.start_state = $("#start-state").val();
}.bind(this));
}
defineHyperparameterControls() {
@@ -338,8 +344,6 @@ class ControlPanel {
$('#clear-env').click( () => {
env.reset(true, false);
this.stats_panel.reset();
env.auto_reset = false;
$('#auto-reset').prop('checked', false);;
});
$('#random-walls').click( function() {
this.env_controller.randomizeWalls();

View File

@@ -19,7 +19,6 @@ class WorldEnvironment extends Environment{
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;
@@ -59,24 +58,37 @@ 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);
}
}
}
OriginOfLife() {
var center = this.grid_map.getCenter();
var org = new Organism(center[0], center[1], this);
org.anatomy.addDefaultCell(CellStates.mouth, 0, 0);
org.anatomy.addDefaultCell(CellStates.producer, 1, 1);
org.anatomy.addDefaultCell(CellStates.producer, -1, -1);
this.addOrganism(org);
FossilRecord.addSpecies(org, null);
switch (WorldConfig.start_state){
case 'simple-prod':
var org = new Organism(center[0], center[1], this);
org.anatomy.addDefaultCell(CellStates.mouth, 0, 0);
org.anatomy.addDefaultCell(CellStates.producer, 1, 1);
org.anatomy.addDefaultCell(CellStates.producer, -1, -1);
this.addOrganism(org);
FossilRecord.addSpecies(org, null);
break;
case 'random-orgs':
break;
case 'no-orgs':
break;
}
}
addOrganism(organism) {

View File

@@ -1,6 +1,9 @@
const WorldConfig = {
headless: false,
clear_walls_on_reset: false,
start_state: 'simple-prod',
auto_reset: true,
auto_pause: false,
}
module.exports = WorldConfig;