Added auto food generation
This commit is contained in:
3
dist/index.html
vendored
3
dist/index.html
vendored
@@ -189,6 +189,9 @@
|
|||||||
<br>
|
<br>
|
||||||
<label for="look-range" title='How far an eye cell can see (in number of cells)'>Look range:</label>
|
<label for="look-range" title='How far an eye cell can see (in number of cells)'>Look range:</label>
|
||||||
<input type="number" id="look-range" min="1" max="50" value=20 step="1">
|
<input type="number" id="look-range" min="1" max="50" value=20 step="1">
|
||||||
|
<br>
|
||||||
|
<label for="food-drop-rate" title='Rate at which food is automatically generated and dropped in the world'>Auto food drop rate:</label>
|
||||||
|
<input type="number" id="food-drop-rate" value=0 max="1000">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class='right-half'>
|
<div class='right-half'>
|
||||||
|
|||||||
2
dist/js/bundle.js
vendored
2
dist/js/bundle.js
vendored
File diff suppressed because one or more lines are too long
@@ -106,6 +106,9 @@ class ControlPanel {
|
|||||||
$('#look-range').change(function() {
|
$('#look-range').change(function() {
|
||||||
Hyperparams.lookRange = $('#look-range').val();
|
Hyperparams.lookRange = $('#look-range').val();
|
||||||
});
|
});
|
||||||
|
$('#food-drop-rate').change(function() {
|
||||||
|
Hyperparams.foodDropProb = $('#food-drop-rate').val();
|
||||||
|
});
|
||||||
|
|
||||||
$('#evolved-mutation').change( function() {
|
$('#evolved-mutation').change( function() {
|
||||||
if (this.checked) {
|
if (this.checked) {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ const GridMap = require('../Grid/GridMap');
|
|||||||
const Organism = require('../Organism/Organism');
|
const Organism = require('../Organism/Organism');
|
||||||
const CellStates = require('../Organism/Cell/CellStates');
|
const CellStates = require('../Organism/Cell/CellStates');
|
||||||
const EnvironmentController = require('../Controllers/EnvironmentController');
|
const EnvironmentController = require('../Controllers/EnvironmentController');
|
||||||
|
const Hyperparams = require('../Hyperparameters.js');
|
||||||
|
const Cell = require('../Organism/Cell/GridCell');
|
||||||
|
|
||||||
class WorldEnvironment extends Environment{
|
class WorldEnvironment extends Environment{
|
||||||
constructor(cell_size) {
|
constructor(cell_size) {
|
||||||
@@ -29,6 +31,9 @@ class WorldEnvironment extends Environment{
|
|||||||
to_remove.push(i);
|
to_remove.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Hyperparams.foodDropProb > 0) {
|
||||||
|
this.generateFood();
|
||||||
|
}
|
||||||
this.removeOrganisms(to_remove);
|
this.removeOrganisms(to_remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +99,21 @@ class WorldEnvironment extends Environment{
|
|||||||
this.organisms = [];
|
this.organisms = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateFood() {
|
||||||
|
var num_food = Math.max(Math.floor(this.grid_map.cols*this.grid_map.rows*Hyperparams.foodDropProb/50000), 1)
|
||||||
|
var prob = Hyperparams.foodDropProb;
|
||||||
|
for (var i=0; i<num_food; i++) {
|
||||||
|
if (Math.random() <= prob){
|
||||||
|
var c=Math.floor(Math.random() * this.grid_map.cols);
|
||||||
|
var r=Math.floor(Math.random() * this.grid_map.rows);
|
||||||
|
|
||||||
|
if (this.grid_map.cellAt(c, r).state == CellStates.empty){
|
||||||
|
this.changeCell(c, r, CellStates.food, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reset(clear_walls=true) {
|
reset(clear_walls=true) {
|
||||||
this.organisms = [];
|
this.organisms = [];
|
||||||
this.grid_map.fillGrid(CellStates.empty);
|
this.grid_map.fillGrid(CellStates.empty);
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ const Hyperparams = {
|
|||||||
this.instaKill = false;
|
this.instaKill = false;
|
||||||
|
|
||||||
this.lookRange = 20;
|
this.lookRange = 20;
|
||||||
|
|
||||||
|
this.foodDropProb = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
balanceMutationProbs : function(choice) {
|
balanceMutationProbs : function(choice) {
|
||||||
|
|||||||
Reference in New Issue
Block a user