Randomized Creature Generation

Adds a random organism generator that is accessible through the editor control panel.
This generator gives the user to generate an entire world of random organisms for selection to act upon.
This commit is contained in:
Chris Gallegos
2021-11-21 01:36:20 -08:00
parent 2ef721682a
commit 869cc85d04
12 changed files with 227 additions and 28 deletions

View File

@@ -6,7 +6,8 @@ const Modes = {
Select: 4,
Edit: 5,
Clone: 6,
Drag: 7
Drag: 7,
Randomize: 8,
}
module.exports = Modes;

View File

@@ -1,6 +1,7 @@
const Hyperparams = require("../Hyperparameters");
const Modes = require("./ControlModes");
const StatsPanel = require("../Stats/StatsPanel");
const RandomOrganismGenerator = require("../Organism/RandomOrganismGenerator")
class ControlPanel {
constructor(engine) {
@@ -21,7 +22,7 @@ class ControlPanel {
this.stats_panel = new StatsPanel(this.engine.env);
this.headless_opacity = 1;
this.opacity_change_rate = -0.8;
this.paused=false;
//this.paused=false;
}
defineMinMaxControls(){
@@ -84,17 +85,12 @@ class ControlPanel {
}
$('#fps').text("Target FPS: "+this.fps);
}.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");
@@ -263,6 +259,9 @@ class ControlPanel {
self.setMode(Modes.Edit);
self.editor_controller.setEditorPanel();
break;
case "randomize":
self.setMode(Modes.Randomize);
self.editor_controller.setRandomizePanel();
case "drop-org":
self.setMode(Modes.Clone);
self.env_controller.org_to_clone = self.engine.organism_editor.getCopyOfOrg();
@@ -298,6 +297,24 @@ class ControlPanel {
this.engine.organism_editor.clear();
this.editor_controller.setEditorPanel();
}.bind(this));
document.getElementById("random-width").addEventListener('input', function() {
var width = 2 * this.value + 1;
$('#random-width-display').text(width);
RandomOrganismGenerator.organismLayers = this.value;
});
document.getElementById("cell-spawn-chance").addEventListener("input", function() {
var value = parseFloat(this.value);
$('#spawn-chance-display').text((value * 100).toFixed(1) + "%");
RandomOrganismGenerator.cellSpawnChance = value;
});
$('#generate-random').click( function() {
this.engine.organism_editor.createRandom();
}.bind(this));
$('#create-random-world').click( function() {
this.setPaused(true);
this.engine.organism_editor.createRandomWorld(this.engine.env);
}.bind(this));
}
defineChallenges() {
@@ -307,6 +324,20 @@ class ControlPanel {
});
}
setPaused(paused) {
if (paused) {
$('.pause-button').find("i").removeClass("fa-pause");
$('.pause-button').find("i").addClass("fa-play");
this.engine.stop();
}
else if (!paused) {
$('.pause-button').find("i").addClass("fa-pause");
$('.pause-button').find("i").removeClass("fa-play");
this.engine.start(this.fps);
}
}
setMode(mode) {
this.env_controller.mode = mode;
this.editor_controller.mode = mode;
@@ -325,7 +356,7 @@ class ControlPanel {
}
updateHeadlessIcon(delta_time) {
if (this.paused)
if (this.engine.running)
return;
var op = this.headless_opacity + (this.opacity_change_rate*delta_time/1000);
if (op <= 0.4){

View File

@@ -108,6 +108,7 @@ class EditorController extends CanvasController{
clearDetailsPanel() {
$('#organism-details').css('display', 'none');
$('#edit-organism-details').css('display', 'none');
$('#randomize-organism-details').css('display', 'none');
}
setDetailsPanel() {
@@ -193,6 +194,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;

View File

@@ -122,21 +122,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:
@@ -151,6 +137,26 @@ 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 (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();
}
}
dropCellType(col, row, state, killBlocking=false) {
for (var loc of Neighbors.allSelf){
var c=col + loc[0];