BlueGit

blue-star cellular-evolution

Merge branch 'biases'

timfa Tim · pushed by timfa

Authored 2021-10-16 · 5 years ago

Hash
7d07d4a8c938edca1ea5bd58fa0a81ff3ba46184
2 files changed +13 −2
src/creature.js +1 −1
@@ -154,7 +154,7 @@ var creature =
154 154
155 155 cellInstance.lastSum = currentSum;
156 156
157 return currentSum;
157 return currentSum + this.dna[cellInstance.cellRef].bias;
158 158 },
159 159
160 160 findCellInstanceByCellId: function(id)
@@ -154,7 +154,7 @@ var creature =
154
154
155 cellInstance.lastSum = currentSum;
155 cellInstance.lastSum = currentSum;
156
156
157 return currentSum;
157 return currentSum + this.dna[cellInstance.cellRef].bias;
158 },
158 },
159
159
160 findCellInstanceByCellId: function(id)
160 findCellInstanceByCellId: function(id)
src/dnastring.js +12 −1
@@ -94,6 +94,8 @@ function MutateDNA(dna)
94 94 {
95 95 var rand = Math.random();
96 96
97 MutateBiases(dna, 1 - rand);
98
97 99 if(rand < 0.1)
98 100 AddRandomCell(dna);
99 101
@@ -104,6 +106,14 @@ function MutateDNA(dna)
104 106 MutateSynapses(dna, 1 - rand);
105 107 }
106 108
109 function MutateBiases(dna, strength)
110 {
111 for(var i = 0; i < dna.length; i++)
112 {
113 dna[i].bias += -(strength/2) + (Math.random() * strength);
114 }
115 }
116
107 117 function MutateSynapses(dna, strength)
108 118 {
109 119 for(var i = 0; i < dna.length; i++)
@@ -227,7 +237,8 @@ function AddRandomCell(dna)
227 237 id: id,
228 238 type: TYPES[selected],
229 239 inputs: [],
230 pos: pos
240 pos: pos,
241 bias: 0
231 242 }
232 243
233 244 dna.push(cell);
@@ -94,6 +94,8 @@ function MutateDNA(dna)
94{
94{
95 var rand = Math.random();
95 var rand = Math.random();
96
96
97 MutateBiases(dna, 1 - rand);
98
97 if(rand < 0.1)
99 if(rand < 0.1)
98 AddRandomCell(dna);
100 AddRandomCell(dna);
99
101
@@ -104,6 +106,14 @@ function MutateDNA(dna)
104 MutateSynapses(dna, 1 - rand);
106 MutateSynapses(dna, 1 - rand);
105}
107}
106
108
109function MutateBiases(dna, strength)
110{
111 for(var i = 0; i < dna.length; i++)
112 {
113 dna[i].bias += -(strength/2) + (Math.random() * strength);
114 }
115}
116
107function MutateSynapses(dna, strength)
117function MutateSynapses(dna, strength)
108{
118{
109 for(var i = 0; i < dna.length; i++)
119 for(var i = 0; i < dna.length; i++)
@@ -227,7 +237,8 @@ function AddRandomCell(dna)
227 id: id,
237 id: id,
228 type: TYPES[selected],
238 type: TYPES[selected],
229 inputs: [],
239 inputs: [],
230 pos: pos
240 pos: pos,
241 bias: 0
231 }
242 }
232
243
233 dna.push(cell);
244 dna.push(cell);