BlueGit

blue-star cellular-evolution

build

timfa Tim · pushed by timfa

Authored 2021-10-16 · 5 years ago

Hash
2997d0695ebda81667acaf51d6df51d8c7d128fb
Parent
c8ac507a
2 files changed +27 −6
js/game.js +22 −6
@@ -10,8 +10,8 @@ var cell =
10 10 cellRef: -1,
11 11 currentSensorSignal: 0, //only used for sensors, else forever zero
12 12 lastSum: 0, //used for debug purposes
13 energy: 100,
14 maxEnergy: 100,
13 energy: 1,
14 maxEnergy: 1,
15 15 debugShouldDraw: false,
16 16
17 17 start: function()
@@ -58,7 +58,7 @@ var cell =
58 58 if(other.parentCreature == this.parentCreature)
59 59 return;
60 60
61 this.parentCreature.gainEnergy(10);
61 this.parentCreature.gainEnergy(this.maxEnergy / 3);
62 62 other.destroy();
63 63 }
64 64 },
@@ -252,7 +252,7 @@ var creature =
252 252
253 253 cellInstance.lastSum = currentSum;
254 254
255 return currentSum;
255 return currentSum + this.dna[cellInstance.cellRef].bias;
256 256 },
257 257
258 258 findCellInstanceByCellId: function(id)
@@ -372,6 +372,8 @@ function MutateDNA(dna)
372 372 {
373 373 var rand = Math.random();
374 374
375 MutateBiases(dna, 1 - rand);
376
375 377 if(rand < 0.1)
376 378 AddRandomCell(dna);
377 379
@@ -382,6 +384,14 @@ function MutateDNA(dna)
382 384 MutateSynapses(dna, 1 - rand);
383 385 }
384 386
387 function MutateBiases(dna, strength)
388 {
389 for(var i = 0; i < dna.length; i++)
390 {
391 dna[i].bias += -(strength/2) + (Math.random() * strength);
392 }
393 }
394
385 395 function MutateSynapses(dna, strength)
386 396 {
387 397 for(var i = 0; i < dna.length; i++)
@@ -505,7 +515,8 @@ function AddRandomCell(dna)
505 515 id: id,
506 516 type: TYPES[selected],
507 517 inputs: [],
508 pos: pos
518 pos: pos,
519 bias: 0
509 520 }
510 521
511 522 dna.push(cell);
@@ -753,10 +764,15 @@ function gameStart()
753 764 GameAudio.init(sounds, soundsFolder);
754 765
755 766 p1 = GameObject.create(gemSpawner, GameWindow.width / 2, GameWindow.height / 2, null, 500);
756 tester = GameObject.create(creature, GameWindow.width / 2, GameWindow.height / 2, null, 500);
767 tester = GameObject.create(creature, GameWindow.width / 3, GameWindow.height / 2, null, 500);
757 768
758 769 tester.dna = GenerateNewDNA();
759 770 tester.initCells();
771
772 tester2 = GameObject.create(creature, (GameWindow.width / 3) * 2, GameWindow.height / 2, null, 500);
773
774 tester2.dna = GenerateNewDNA();
775 tester2.initCells();
760 776 }
761 777
762 778 function update(deltaTime)
@@ -10,8 +10,8 @@ var cell =
10 cellRef: -1,
10 cellRef: -1,
11 currentSensorSignal: 0, //only used for sensors, else forever zero
11 currentSensorSignal: 0, //only used for sensors, else forever zero
12 lastSum: 0, //used for debug purposes
12 lastSum: 0, //used for debug purposes
13 energy: 100,
13 energy: 1,
14 maxEnergy: 100,
14 maxEnergy: 1,
15 debugShouldDraw: false,
15 debugShouldDraw: false,
16
16
17 start: function()
17 start: function()
@@ -58,7 +58,7 @@ var cell =
58 if(other.parentCreature == this.parentCreature)
58 if(other.parentCreature == this.parentCreature)
59 return;
59 return;
60
60
61 this.parentCreature.gainEnergy(10);
61 this.parentCreature.gainEnergy(this.maxEnergy / 3);
62 other.destroy();
62 other.destroy();
63 }
63 }
64 },
64 },
@@ -252,7 +252,7 @@ var creature =
252
252
253 cellInstance.lastSum = currentSum;
253 cellInstance.lastSum = currentSum;
254
254
255 return currentSum;
255 return currentSum + this.dna[cellInstance.cellRef].bias;
256 },
256 },
257
257
258 findCellInstanceByCellId: function(id)
258 findCellInstanceByCellId: function(id)
@@ -372,6 +372,8 @@ function MutateDNA(dna)
372{
372{
373 var rand = Math.random();
373 var rand = Math.random();
374
374
375 MutateBiases(dna, 1 - rand);
376
375 if(rand < 0.1)
377 if(rand < 0.1)
376 AddRandomCell(dna);
378 AddRandomCell(dna);
377
379
@@ -382,6 +384,14 @@ function MutateDNA(dna)
382 MutateSynapses(dna, 1 - rand);
384 MutateSynapses(dna, 1 - rand);
383}
385}
384
386
387function MutateBiases(dna, strength)
388{
389 for(var i = 0; i < dna.length; i++)
390 {
391 dna[i].bias += -(strength/2) + (Math.random() * strength);
392 }
393}
394
385function MutateSynapses(dna, strength)
395function MutateSynapses(dna, strength)
386{
396{
387 for(var i = 0; i < dna.length; i++)
397 for(var i = 0; i < dna.length; i++)
@@ -505,7 +515,8 @@ function AddRandomCell(dna)
505 id: id,
515 id: id,
506 type: TYPES[selected],
516 type: TYPES[selected],
507 inputs: [],
517 inputs: [],
508 pos: pos
518 pos: pos,
519 bias: 0
509 }
520 }
510
521
511 dna.push(cell);
522 dna.push(cell);
@@ -753,10 +764,15 @@ function gameStart()
753 GameAudio.init(sounds, soundsFolder);
764 GameAudio.init(sounds, soundsFolder);
754
765
755 p1 = GameObject.create(gemSpawner, GameWindow.width / 2, GameWindow.height / 2, null, 500);
766 p1 = GameObject.create(gemSpawner, GameWindow.width / 2, GameWindow.height / 2, null, 500);
756 tester = GameObject.create(creature, GameWindow.width / 2, GameWindow.height / 2, null, 500);
767 tester = GameObject.create(creature, GameWindow.width / 3, GameWindow.height / 2, null, 500);
757
768
758 tester.dna = GenerateNewDNA();
769 tester.dna = GenerateNewDNA();
759 tester.initCells();
770 tester.initCells();
771
772 tester2 = GameObject.create(creature, (GameWindow.width / 3) * 2, GameWindow.height / 2, null, 500);
773
774 tester2.dna = GenerateNewDNA();
775 tester2.initCells();
760}
776}
761
777
762function update(deltaTime)
778function update(deltaTime)
js/lastbuild.txt +5 −0
@@ -96,3 +96,8 @@
96 96 -13-10-2021- 15:14
97 97 -13-10-2021- 15:19
98 98 -13-10-2021- 15:20
99 -13-10-2021- 15:53
100 -13-10-2021- 15:54
101 -13-10-2021- 15:55
102 -13-10-2021- 18:00
103 -16-10-2021- 21:20
@@ -96,3 +96,8 @@
96-13-10-2021- 15:14
96-13-10-2021- 15:14
97-13-10-2021- 15:19
97-13-10-2021- 15:19
98-13-10-2021- 15:20
98-13-10-2021- 15:20
99-13-10-2021- 15:53
100-13-10-2021- 15:54
101-13-10-2021- 15:55
102-13-10-2021- 18:00
103-16-10-2021- 21:20