energy consumption
The contents of this binary file are not shown.
@@ -10,6 +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
15
14
16
start: function()
15
17
{
@@ -32,12 +34,14 @@ var cell =
32
34
switch(this.type)
33
35
{
34
36
case TYPES.LOCOMOTOR:
37
var power = this.parentCreature.consumeEnergy(strength * deltaTime)
35
38
var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);
36
39
37
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime));
40
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime * power));
38
41
break;
39
42
case TYPES.ROTATOR:
40
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50;
43
var power = this.parentCreature.consumeEnergy(strength * deltaTime)
44
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50 * power;
41
45
break;
42
46
}
43
47
},
@@ -60,6 +64,9 @@ var cell =
60
64
61
65
if(this.type == TYPES.LOCOMOTOR)
62
66
this.transform.rotation = rotated.toAngle() - 90;
67
68
if(this.type == TYPES.STOMACH)
69
this.currentSensorSignal = this.energy;
63
70
},
64
71
65
72
setType: function(typeID)
@@ -128,6 +135,33 @@ var creature =
128
135
//this.transform.position = this.transform.position.add(this.transform.forward().stretch(deltaTime * 250))
129
136
},
130
137
138
consumeEnergy: function(energyNeeded) //returns a number between 0 and 1. 0 meaning no energy was consumed (because we ran out), 1 means all of the energy was consumed.
139
{
140
var stomachRef = -1;
141
var amt = 0;
142
143
for(var i = 0; i < this.cellInstances.length; i++)
144
{
145
if(this.cellInstances[i].type == TYPES.STOMACH)
146
{
147
if(this.cellInstances[i].energy > amt)
148
{
149
stomachRef = i;
150
amt = this.cellInstances[i].energy;
151
}
152
}
153
}
154
155
if(stomachRef == -1)
156
return 0;
157
158
var efficiency = Math.min(1, this.cellInstances[stomachRef].energy / energyNeeded)
159
160
this.cellInstances[stomachRef].energy = Math.max(0, this.cellInstances[stomachRef].energy - energyNeeded)
161
162
return efficiency;
163
},
164
131
165
draw: function()
132
166
{
133
167
for(var i = 0; i < this.cellInstances.length; i++)
@@ -329,7 +363,7 @@ function AddRandomSynapse(dna, att = 0)
329
363
senders.push(i);
330
364
}
331
365
332
if(dna[i].type == TYPES.EYE)
366
if(dna[i].type == TYPES.EYE || dna[i].type == TYPES.STOMACH || dna[i].type == TYPES.NOSE || dna[i].type == TYPES.HEATSENSOR)
333
367
{
334
368
senders.push(i);
335
369
}
@@ -437,18 +471,22 @@ var TYPES =
437
471
ROTATOR: 4,
438
472
EYE: 5,
439
473
STOMACH: 6,
440
MEAT: 7
474
MEAT: 7,
475
NOSE: 8,
476
HEATSENSOR: 9
441
477
}
442
478
443
479
var Weights =
444
480
{
445
BRAIN: 1,
481
BRAIN: 1.2,
446
482
MOUTH: 2,
447
483
LOCOMOTOR: 2,
448
484
ROTATOR: 1,
449
EYE: 2,
485
EYE: 2.4,
450
486
STOMACH: 3,
451
MEAT: 4
487
MEAT: 4,
488
NOSE: 1.5,
489
HEATSENSOR: 1.3
452
490
}
453
491
454
492
@@ -632,7 +670,7 @@ var gemSpawner =
632
670
633
671
var s_head = new image("images/head.png", 4, 4);
634
672
var s_orb = new image("images/orb.png", 8, 4);
635
var s_cell = new image("images/cells.png", 8, 4);
673
var s_cell = new image("images/cells.png", 12, 4);
636
674
var s_gem = new image("images/gems.png", 72, 6);
637
675
638
676
/**
@@ -10,6 +10,8 @@ var cell =10
cellRef: -1,10
cellRef: -1,11
currentSensorSignal: 0, //only used for sensors, else forever zero11
currentSensorSignal: 0, //only used for sensors, else forever zero12
lastSum: 0, //used for debug purposes12
lastSum: 0, //used for debug purposes13
energy: 100,14
maxEnergy: 100,13
15
14
start: function()16
start: function()15
{17
{@@ -32,12 +34,14 @@ var cell =32
switch(this.type)34
switch(this.type)33
{35
{34
case TYPES.LOCOMOTOR:36
case TYPES.LOCOMOTOR:37
var power = this.parentCreature.consumeEnergy(strength * deltaTime)35
var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);38
var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);36
39
37
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime));40
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime * power));38
break;41
break;39
case TYPES.ROTATOR:42
case TYPES.ROTATOR:40
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50;43
var power = this.parentCreature.consumeEnergy(strength * deltaTime)44
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50 * power;41
break;45
break;42
}46
}43
},47
},@@ -60,6 +64,9 @@ var cell =60
64
61
if(this.type == TYPES.LOCOMOTOR)65
if(this.type == TYPES.LOCOMOTOR)62
this.transform.rotation = rotated.toAngle() - 90;66
this.transform.rotation = rotated.toAngle() - 90;67
68
if(this.type == TYPES.STOMACH)69
this.currentSensorSignal = this.energy;63
},70
},64
71
65
setType: function(typeID)72
setType: function(typeID)@@ -128,6 +135,33 @@ var creature =128
//this.transform.position = this.transform.position.add(this.transform.forward().stretch(deltaTime * 250))135
//this.transform.position = this.transform.position.add(this.transform.forward().stretch(deltaTime * 250))129
},136
},130
137
138
consumeEnergy: function(energyNeeded) //returns a number between 0 and 1. 0 meaning no energy was consumed (because we ran out), 1 means all of the energy was consumed.139
{140
var stomachRef = -1;141
var amt = 0;142
143
for(var i = 0; i < this.cellInstances.length; i++)144
{145
if(this.cellInstances[i].type == TYPES.STOMACH)146
{147
if(this.cellInstances[i].energy > amt)148
{149
stomachRef = i;150
amt = this.cellInstances[i].energy;151
}152
}153
}154
155
if(stomachRef == -1)156
return 0;157
158
var efficiency = Math.min(1, this.cellInstances[stomachRef].energy / energyNeeded)159
160
this.cellInstances[stomachRef].energy = Math.max(0, this.cellInstances[stomachRef].energy - energyNeeded)161
162
return efficiency;163
},164
131
draw: function()165
draw: function()132
{166
{133
for(var i = 0; i < this.cellInstances.length; i++)167
for(var i = 0; i < this.cellInstances.length; i++)@@ -329,7 +363,7 @@ function AddRandomSynapse(dna, att = 0)329
senders.push(i);363
senders.push(i);330
}364
}331
365
332
if(dna[i].type == TYPES.EYE)366
if(dna[i].type == TYPES.EYE || dna[i].type == TYPES.STOMACH || dna[i].type == TYPES.NOSE || dna[i].type == TYPES.HEATSENSOR)333
{367
{334
senders.push(i);368
senders.push(i);335
}369
}@@ -437,18 +471,22 @@ var TYPES =437
ROTATOR: 4,471
ROTATOR: 4,438
EYE: 5,472
EYE: 5,439
STOMACH: 6,473
STOMACH: 6,440
MEAT: 7474
MEAT: 7,475
NOSE: 8,476
HEATSENSOR: 9441
}477
}442
478
443
var Weights = 479
var Weights = 444
{480
{445
BRAIN: 1,481
BRAIN: 1.2,446
MOUTH: 2,482
MOUTH: 2,447
LOCOMOTOR: 2,483
LOCOMOTOR: 2,448
ROTATOR: 1,484
ROTATOR: 1,449
EYE: 2,485
EYE: 2.4,450
STOMACH: 3,486
STOMACH: 3,451
MEAT: 4487
MEAT: 4,488
NOSE: 1.5,489
HEATSENSOR: 1.3452
}490
}453
491
454
492
@@ -632,7 +670,7 @@ var gemSpawner =632
670
633
var s_head = new image("images/head.png", 4, 4);671
var s_head = new image("images/head.png", 4, 4);634
var s_orb = new image("images/orb.png", 8, 4);672
var s_orb = new image("images/orb.png", 8, 4);635
var s_cell = new image("images/cells.png", 8, 4);673
var s_cell = new image("images/cells.png", 12, 4);636
var s_gem = new image("images/gems.png", 72, 6); 674
var s_gem = new image("images/gems.png", 72, 6); 637
675
638
/**676
/**@@ -74,3 +74,6 @@
74
74
-13-10-2021- 13:47
75
75
-13-10-2021- 13:48
76
76
-13-10-2021- 13:48
77
-13-10-2021- 14:13
78
-13-10-2021- 14:13
79
-13-10-2021- 14:15
@@ -74,3 +74,6 @@74
-13-10-2021- 13:47 74
-13-10-2021- 13:47 75
-13-10-2021- 13:48 75
-13-10-2021- 13:48 76
-13-10-2021- 13:48 76
-13-10-2021- 13:48 77
-13-10-2021- 14:13 78
-13-10-2021- 14:13 79
-13-10-2021- 14:15 @@ -10,6 +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
15
14
16
start: function()
15
17
{
@@ -32,12 +34,14 @@ var cell =
32
34
switch(this.type)
33
35
{
34
36
case TYPES.LOCOMOTOR:
37
var power = this.parentCreature.consumeEnergy(strength * deltaTime)
35
38
var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);
36
39
37
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime));
40
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime * power));
38
41
break;
39
42
case TYPES.ROTATOR:
40
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50;
43
var power = this.parentCreature.consumeEnergy(strength * deltaTime)
44
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50 * power;
41
45
break;
42
46
}
43
47
},
@@ -60,6 +64,9 @@ var cell =
60
64
61
65
if(this.type == TYPES.LOCOMOTOR)
62
66
this.transform.rotation = rotated.toAngle() - 90;
67
68
if(this.type == TYPES.STOMACH)
69
this.currentSensorSignal = this.energy;
63
70
},
64
71
65
72
setType: function(typeID)
@@ -10,6 +10,8 @@ var cell =10
cellRef: -1,10
cellRef: -1,11
currentSensorSignal: 0, //only used for sensors, else forever zero11
currentSensorSignal: 0, //only used for sensors, else forever zero12
lastSum: 0, //used for debug purposes12
lastSum: 0, //used for debug purposes13
energy: 100,14
maxEnergy: 100,13
15
14
start: function()16
start: function()15
{17
{@@ -32,12 +34,14 @@ var cell =32
switch(this.type)34
switch(this.type)33
{35
{34
case TYPES.LOCOMOTOR:36
case TYPES.LOCOMOTOR:37
var power = this.parentCreature.consumeEnergy(strength * deltaTime)35
var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);38
var rotated = this.localPos.rotate(this.parentCreature.transform.rotation);36
39
37
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime));40
this.parentCreature.transform.position = this.parentCreature.transform.position.subtract(rotated.stretch(deltaTime * power));38
break;41
break;39
case TYPES.ROTATOR:42
case TYPES.ROTATOR:40
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50;43
var power = this.parentCreature.consumeEnergy(strength * deltaTime)44
this.parentCreature.transform.rotation += (strength - 0.5) * deltaTime * 50 * power;41
break;45
break;42
}46
}43
},47
},@@ -60,6 +64,9 @@ var cell =60
64
61
if(this.type == TYPES.LOCOMOTOR)65
if(this.type == TYPES.LOCOMOTOR)62
this.transform.rotation = rotated.toAngle() - 90;66
this.transform.rotation = rotated.toAngle() - 90;67
68
if(this.type == TYPES.STOMACH)69
this.currentSensorSignal = this.energy;63
},70
},64
71
65
setType: function(typeID)72
setType: function(typeID)@@ -57,6 +57,33 @@ var creature =
57
57
//this.transform.position = this.transform.position.add(this.transform.forward().stretch(deltaTime * 250))
58
58
},
59
59
60
consumeEnergy: function(energyNeeded) //returns a number between 0 and 1. 0 meaning no energy was consumed (because we ran out), 1 means all of the energy was consumed.
61
{
62
var stomachRef = -1;
63
var amt = 0;
64
65
for(var i = 0; i < this.cellInstances.length; i++)
66
{
67
if(this.cellInstances[i].type == TYPES.STOMACH)
68
{
69
if(this.cellInstances[i].energy > amt)
70
{
71
stomachRef = i;
72
amt = this.cellInstances[i].energy;
73
}
74
}
75
}
76
77
if(stomachRef == -1)
78
return 0;
79
80
var efficiency = Math.min(1, this.cellInstances[stomachRef].energy / energyNeeded)
81
82
this.cellInstances[stomachRef].energy = Math.max(0, this.cellInstances[stomachRef].energy - energyNeeded)
83
84
return efficiency;
85
},
86
60
87
draw: function()
61
88
{
62
89
for(var i = 0; i < this.cellInstances.length; i++)
@@ -57,6 +57,33 @@ var creature =57
//this.transform.position = this.transform.position.add(this.transform.forward().stretch(deltaTime * 250))57
//this.transform.position = this.transform.position.add(this.transform.forward().stretch(deltaTime * 250))58
},58
},59
59
60
consumeEnergy: function(energyNeeded) //returns a number between 0 and 1. 0 meaning no energy was consumed (because we ran out), 1 means all of the energy was consumed.61
{62
var stomachRef = -1;63
var amt = 0;64
65
for(var i = 0; i < this.cellInstances.length; i++)66
{67
if(this.cellInstances[i].type == TYPES.STOMACH)68
{69
if(this.cellInstances[i].energy > amt)70
{71
stomachRef = i;72
amt = this.cellInstances[i].energy;73
}74
}75
}76
77
if(stomachRef == -1)78
return 0;79
80
var efficiency = Math.min(1, this.cellInstances[stomachRef].energy / energyNeeded)81
82
this.cellInstances[stomachRef].energy = Math.max(0, this.cellInstances[stomachRef].energy - energyNeeded)83
84
return efficiency;85
},86
60
draw: function()87
draw: function()61
{88
{62
for(var i = 0; i < this.cellInstances.length; i++)89
for(var i = 0; i < this.cellInstances.length; i++)@@ -134,7 +134,7 @@ function AddRandomSynapse(dna, att = 0)
134
134
senders.push(i);
135
135
}
136
136
137
if(dna[i].type == TYPES.EYE)
137
if(dna[i].type == TYPES.EYE || dna[i].type == TYPES.STOMACH || dna[i].type == TYPES.NOSE || dna[i].type == TYPES.HEATSENSOR)
138
138
{
139
139
senders.push(i);
140
140
}
@@ -242,18 +242,22 @@ var TYPES =
242
242
ROTATOR: 4,
243
243
EYE: 5,
244
244
STOMACH: 6,
245
MEAT: 7
245
MEAT: 7,
246
NOSE: 8,
247
HEATSENSOR: 9
246
248
}
247
249
248
250
var Weights =
249
251
{
250
BRAIN: 1,
252
BRAIN: 1.2,
251
253
MOUTH: 2,
252
254
LOCOMOTOR: 2,
253
255
ROTATOR: 1,
254
EYE: 2,
256
EYE: 2.4,
255
257
STOMACH: 3,
256
MEAT: 4
258
MEAT: 4,
259
NOSE: 1.5,
260
HEATSENSOR: 1.3
257
261
}
258
262
259
263
@@ -134,7 +134,7 @@ function AddRandomSynapse(dna, att = 0)134
senders.push(i);134
senders.push(i);135
}135
}136
136
137
if(dna[i].type == TYPES.EYE)137
if(dna[i].type == TYPES.EYE || dna[i].type == TYPES.STOMACH || dna[i].type == TYPES.NOSE || dna[i].type == TYPES.HEATSENSOR)138
{138
{139
senders.push(i);139
senders.push(i);140
}140
}@@ -242,18 +242,22 @@ var TYPES =242
ROTATOR: 4,242
ROTATOR: 4,243
EYE: 5,243
EYE: 5,244
STOMACH: 6,244
STOMACH: 6,245
MEAT: 7245
MEAT: 7,246
NOSE: 8,247
HEATSENSOR: 9246
}248
}247
249
248
var Weights = 250
var Weights = 249
{251
{250
BRAIN: 1,252
BRAIN: 1.2,251
MOUTH: 2,253
MOUTH: 2,252
LOCOMOTOR: 2,254
LOCOMOTOR: 2,253
ROTATOR: 1,255
ROTATOR: 1,254
EYE: 2,256
EYE: 2.4,255
STOMACH: 3,257
STOMACH: 3,256
MEAT: 4258
MEAT: 4,259
NOSE: 1.5,260
HEATSENSOR: 1.3257
}261
}258
262
259
263
@@ -4,5 +4,5 @@
4
4
5
5
var s_head = new image("images/head.png", 4, 4);
6
6
var s_orb = new image("images/orb.png", 8, 4);
7
var s_cell = new image("images/cells.png", 8, 4);
7
var s_cell = new image("images/cells.png", 12, 4);
8
8
var s_gem = new image("images/gems.png", 72, 6);
@@ -4,5 +4,5 @@4
4
5
var s_head = new image("images/head.png", 4, 4);5
var s_head = new image("images/head.png", 4, 4);6
var s_orb = new image("images/orb.png", 8, 4);6
var s_orb = new image("images/orb.png", 8, 4);7
var s_cell = new image("images/cells.png", 8, 4);7
var s_cell = new image("images/cells.png", 12, 4);8
var s_gem = new image("images/gems.png", 72, 6);8
var s_gem = new image("images/gems.png", 72, 6);