cleaned random creature generation
This commit is contained in:
@@ -7,7 +7,6 @@ const Modes = {
|
||||
Edit: 5,
|
||||
Clone: 6,
|
||||
Drag: 7,
|
||||
Randomize: 8,
|
||||
}
|
||||
|
||||
module.exports = Modes;
|
||||
@@ -14,7 +14,6 @@ class ControlPanel {
|
||||
this.defineHyperparameterControls();
|
||||
this.defineWorldControls();
|
||||
this.defineModeControls();
|
||||
this.defineChallenges();
|
||||
this.fps = engine.fps;
|
||||
this.organism_record=0;
|
||||
this.env_controller = this.engine.env.controller;
|
||||
@@ -198,11 +197,15 @@ class ControlPanel {
|
||||
});
|
||||
$('#clear-walls-reset').change(function() {
|
||||
WorldConfig.clear_walls_on_reset = this.checked;
|
||||
})
|
||||
|
||||
$('#start-state').change ( function() {
|
||||
WorldConfig.start_state = $("#start-state").val();
|
||||
}.bind(this));
|
||||
});
|
||||
$('#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])
|
||||
});
|
||||
}
|
||||
|
||||
defineHyperparameterControls() {
|
||||
@@ -226,7 +229,6 @@ class ControlPanel {
|
||||
Hyperparams.foodDropProb = $('#food-drop-rate').val();
|
||||
});
|
||||
$('#extra-mover-cost').change(function() {
|
||||
console.log(parseInt($('#extra-mover-cost').val()))
|
||||
Hyperparams.extraMoverFoodCost = parseInt($('#extra-mover-cost').val());
|
||||
});
|
||||
|
||||
@@ -346,9 +348,6 @@ class ControlPanel {
|
||||
case "edit":
|
||||
self.setMode(Modes.Edit);
|
||||
break;
|
||||
case "randomize":
|
||||
self.setMode(Modes.Randomize);
|
||||
self.editor_controller.setRandomizePanel();
|
||||
case "drop-org":
|
||||
self.setMode(Modes.Clone);
|
||||
break;
|
||||
@@ -358,7 +357,6 @@ class ControlPanel {
|
||||
$('.edit-mode-btn').removeClass('selected');
|
||||
$('.'+this.id).addClass('selected');
|
||||
});
|
||||
|
||||
$('.reset-view').click( function(){
|
||||
this.env_controller.resetView();
|
||||
}.bind(this));
|
||||
@@ -382,25 +380,13 @@ 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();
|
||||
this.editor_controller.refreshDetailsPanel();
|
||||
}.bind(this));
|
||||
|
||||
$('#create-random-world').click( function() {
|
||||
this.setPaused(true);
|
||||
this.engine.organism_editor.createRandomWorld(this.engine.env);
|
||||
$('.reset-random').click( function() {
|
||||
this.engine.organism_editor.resetWithRandomOrgs(this.engine.env);
|
||||
}.bind(this));
|
||||
}.bind(this))
|
||||
|
||||
window.onbeforeunload = function (e) {
|
||||
e = e || window.event;
|
||||
@@ -412,13 +398,6 @@ class ControlPanel {
|
||||
};
|
||||
}
|
||||
|
||||
defineChallenges() {
|
||||
$('.challenge-btn').click(function() {
|
||||
$('#challenge-title').text($(this).text());
|
||||
$('#challenge-description').text($(this).val());
|
||||
});
|
||||
}
|
||||
|
||||
setPaused(paused) {
|
||||
|
||||
if (paused) {
|
||||
|
||||
@@ -169,20 +169,23 @@ class EnvironmentController extends CanvasController{
|
||||
|
||||
// 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)){
|
||||
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) {
|
||||
|
||||
@@ -90,7 +90,6 @@ class OrganismEditor extends Environment{
|
||||
}
|
||||
|
||||
createRandom() {
|
||||
|
||||
this.grid_map.fillGrid(CellStates.empty);
|
||||
|
||||
this.organism = RandomOrganismGenerator.generate(this);
|
||||
@@ -98,26 +97,20 @@ class OrganismEditor extends Environment{
|
||||
this.organism.species = new Species(this.organism.anatomy, null, 0);
|
||||
}
|
||||
|
||||
createRandomWorld(worldEnvironment) {
|
||||
resetWithRandomOrgs(env) {
|
||||
let reset_confirmed = env.reset(true, false);
|
||||
if (!reset_confirmed) return;
|
||||
let numOrganisms = parseInt($('#num-random-orgs').val());
|
||||
|
||||
worldEnvironment.clear();
|
||||
let size = Math.ceil(8);
|
||||
|
||||
var numOrganismCols = Math.floor(worldEnvironment.grid_map.cols / this.grid_map.cols);
|
||||
var numOrganismRows = Math.floor(worldEnvironment.grid_map.rows / this.grid_map.rows);
|
||||
var center = this.grid_map.getCenter();
|
||||
|
||||
for (var x = 0; x < numOrganismCols; x++) {
|
||||
for (var y = 0; y < numOrganismRows; y++) {
|
||||
|
||||
var newOrganism = RandomOrganismGenerator.generate(this);
|
||||
//newOrganism.updateGrid();
|
||||
newOrganism.species = new Species(newOrganism.anatomy, null, 0);
|
||||
|
||||
var col = x * this.grid_map.cols + center[0];
|
||||
var row = y * this.grid_map.rows + center[1];
|
||||
worldEnvironment.controller.add_new_species = true;
|
||||
worldEnvironment.controller.dropOrganism(newOrganism, col, row);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,20 +75,12 @@ class WorldEnvironment extends Environment{
|
||||
|
||||
OriginOfLife() {
|
||||
var center = this.grid_map.getCenter();
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
addOrganism(organism) {
|
||||
@@ -146,7 +138,7 @@ 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, !WorldConfig.clear_walls_on_reset);
|
||||
@@ -156,6 +148,7 @@ class WorldEnvironment extends Environment{
|
||||
FossilRecord.clear_record();
|
||||
if (reset_life)
|
||||
this.OriginOfLife();
|
||||
return true;
|
||||
}
|
||||
|
||||
resizeGridColRow(cell_size, cols, rows) {
|
||||
|
||||
@@ -236,7 +236,7 @@ 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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -45,16 +45,7 @@ class RandomOrganismGenerator {
|
||||
}
|
||||
|
||||
// randomize the organism's brain
|
||||
var decisions = organism.brain.decisions;
|
||||
decisions[CellStates.empty.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.food.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.wall.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.mouth.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.producer.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.mover.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.killer.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.armor.name] = Brain.Decision.getRandom();
|
||||
decisions[CellStates.eye.name] = Brain.Decision.getRandom();
|
||||
organism.brain.randomizeDecisions(true);
|
||||
|
||||
return organism;
|
||||
}
|
||||
@@ -71,7 +62,7 @@ class RandomOrganismGenerator {
|
||||
|
||||
}
|
||||
|
||||
RandomOrganismGenerator.organismLayers = 2;
|
||||
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();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const WorldConfig = {
|
||||
headless: false,
|
||||
clear_walls_on_reset: false,
|
||||
start_state: 'simple-prod',
|
||||
auto_reset: true,
|
||||
auto_pause: false,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user