@@ -18,10 +18,9 @@ namespace MaceEvolve.Core.Models
18
18
19
19
#region Properties
20
20
public TStep CurrentStep { get ; private set ; }
21
- public int MaxCreatureAmount { get ; set ; } = 300 ;
21
+ public int MaxCreatureAmount { get ; set ; } = 1000 ;
22
22
public int MaxFoodAmount { get ; set ; } = 350 ;
23
23
public IRectangle WorldBounds { get ; set ; } = new Rectangle ( 0 , 0 , 512 , 512 ) ;
24
- public IRectangle SuccessBounds { get ; set ; }
25
24
public int MinCreatureConnections { get ; set ; } = 4 ;
26
25
public int MaxCreatureConnections { get ; set ; } = 64 ;
27
26
public float CreatureSpeed { get ; set ; }
@@ -48,7 +47,6 @@ namespace MaceEvolve.Core.Models
48
47
49
48
public ReadOnlyCollection < CreatureInput > PossibleCreatureInputs { get ; } = Globals . AllCreatureInputs ;
50
49
public ReadOnlyCollection < CreatureAction > PossibleCreatureActions { get ; } = Globals . AllCreatureActions ;
51
- public bool UseSuccessBounds { get ; set ; }
52
50
public TCreature SelectedCreature
53
51
{
54
52
get
@@ -97,54 +95,6 @@ public virtual void ResetStep(List<TCreature> creatures, List<TFood> food)
97
95
SelectedCreature = null ;
98
96
CurrentStep = CreateStep ( creatures , food ) ;
99
97
}
100
- public virtual Dictionary < TCreature , float > GetFitnesses ( IEnumerable < TCreature > creatures )
101
- {
102
- if ( creatures == null ) { throw new ArgumentNullException ( ) ; }
103
-
104
- if ( ! creatures . Any ( ) )
105
- {
106
- return new Dictionary < TCreature , float > ( ) ;
107
- }
108
-
109
- Dictionary < TCreature , float > successfulCreaturesFitnesses = new Dictionary < TCreature , float > ( ) ;
110
-
111
- if ( UseSuccessBounds )
112
- {
113
- float successBoundsMiddleX = Globals . MiddleX ( SuccessBounds . X , SuccessBounds . Width ) ;
114
- float successBoundsMiddleY = Globals . MiddleY ( SuccessBounds . Y , SuccessBounds . Height ) ;
115
-
116
- foreach ( var creature in creatures )
117
- {
118
- float distanceFromMiddle = Globals . GetDistanceFrom ( creature . MX , creature . MY , successBoundsMiddleX , successBoundsMiddleY ) ;
119
- float successBoundsHypotenuse = Globals . Hypotenuse ( SuccessBounds . Width , SuccessBounds . Height ) ;
120
-
121
- successfulCreaturesFitnesses . Add ( creature , Globals . Map ( distanceFromMiddle , 0 , successBoundsHypotenuse , 1 , 0 ) ) ;
122
- }
123
- }
124
- else
125
- {
126
- float mostEnergy = creatures . Max ( x => x . Energy ) ;
127
- float mostNutrients = creatures . Max ( x => x . Nutrients ) ;
128
- float mostTimesReproduced = creatures . Max ( x => x . TimesReproduced ) ;
129
-
130
- if ( mostEnergy == 0 && mostNutrients == 0 && mostTimesReproduced == 0 )
131
- {
132
- return new Dictionary < TCreature , float > ( ) ;
133
- }
134
-
135
- foreach ( var creature in creatures )
136
- {
137
- float energyFitness = mostEnergy == 0 ? 0 : creature . Energy / mostEnergy ;
138
- float nutrientsFitness = mostNutrients == 0 ? 0 : creature . Nutrients / mostNutrients ;
139
- float timesReproducedFitness = mostTimesReproduced == 0 ? 0 : creature . TimesReproduced / mostTimesReproduced ;
140
- float fitness = Globals . Map ( energyFitness + nutrientsFitness + timesReproducedFitness , 0 , 3 , 0 , 1 ) ;
141
-
142
- successfulCreaturesFitnesses . Add ( creature , fitness ) ;
143
- }
144
- }
145
-
146
- return successfulCreaturesFitnesses ;
147
- }
148
98
public virtual TStep CreateStep ( IEnumerable < TCreature > creatures , IEnumerable < TFood > food )
149
99
{
150
100
return new TStep ( )
@@ -167,9 +117,6 @@ public virtual void NextStep(bool gatherInfoForAllCreatures = false)
167
117
168
118
TCreature newBestCreature = null ;
169
119
170
- float successBoundsMiddleX = Globals . MiddleX ( SuccessBounds . X , SuccessBounds . Width ) ;
171
- float successBoundsMiddleY = Globals . MiddleY ( SuccessBounds . Y , SuccessBounds . Height ) ;
172
-
173
120
Parallel . ForEach ( generatedStep . Creatures , new ParallelOptions ( ) { MaxDegreeOfParallelism = Environment . ProcessorCount } , creature =>
174
121
{
175
122
if ( ! creature . IsDead || creature == BestCreature || creature == SelectedCreature )
@@ -262,17 +209,7 @@ public virtual void NextStep(bool gatherInfoForAllCreatures = false)
262
209
263
210
//Identify the best creature in the step.
264
211
265
- if ( UseSuccessBounds )
266
- {
267
- float distanceFromMiddle = Globals . GetDistanceFrom ( creature . MX , creature . MY , successBoundsMiddleX , successBoundsMiddleY ) ;
268
- float ? newBestCreatureDistanceFromMiddle = newBestCreature == null ? ( float ? ) null : Globals . GetDistanceFrom ( newBestCreature . MX , newBestCreature . MY , successBoundsMiddleX , successBoundsMiddleY ) ;
269
-
270
- if ( newBestCreatureDistanceFromMiddle == null || distanceFromMiddle < newBestCreatureDistanceFromMiddle )
271
- {
272
- newBestCreature = creature ;
273
- }
274
- }
275
- else if ( newBestCreature == null || creature . TimesReproduced > newBestCreature . TimesReproduced )
212
+ if ( newBestCreature == null || creature . TimesReproduced > newBestCreature . TimesReproduced )
276
213
{
277
214
newBestCreature = creature ;
278
215
}
0 commit comments