Skip to content

Commit 268a8c4

Browse files
committed
Remove successbounds functionality
1 parent acc5559 commit 268a8c4

File tree

3 files changed

+4
-87
lines changed

3 files changed

+4
-87
lines changed

MaceEvolve.Core/Models/GameHost.cs

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ namespace MaceEvolve.Core.Models
1818

1919
#region Properties
2020
public TStep CurrentStep { get; private set; }
21-
public int MaxCreatureAmount { get; set; } = 300;
21+
public int MaxCreatureAmount { get; set; } = 1000;
2222
public int MaxFoodAmount { get; set; } = 350;
2323
public IRectangle WorldBounds { get; set; } = new Rectangle(0, 0, 512, 512);
24-
public IRectangle SuccessBounds { get; set; }
2524
public int MinCreatureConnections { get; set; } = 4;
2625
public int MaxCreatureConnections { get; set; } = 64;
2726
public float CreatureSpeed { get; set; }
@@ -48,7 +47,6 @@ namespace MaceEvolve.Core.Models
4847

4948
public ReadOnlyCollection<CreatureInput> PossibleCreatureInputs { get; } = Globals.AllCreatureInputs;
5049
public ReadOnlyCollection<CreatureAction> PossibleCreatureActions { get; } = Globals.AllCreatureActions;
51-
public bool UseSuccessBounds { get; set; }
5250
public TCreature SelectedCreature
5351
{
5452
get
@@ -97,54 +95,6 @@ public virtual void ResetStep(List<TCreature> creatures, List<TFood> food)
9795
SelectedCreature = null;
9896
CurrentStep = CreateStep(creatures, food);
9997
}
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-
}
14898
public virtual TStep CreateStep(IEnumerable<TCreature> creatures, IEnumerable<TFood> food)
14999
{
150100
return new TStep()
@@ -167,9 +117,6 @@ public virtual void NextStep(bool gatherInfoForAllCreatures = false)
167117

168118
TCreature newBestCreature = null;
169119

170-
float successBoundsMiddleX = Globals.MiddleX(SuccessBounds.X, SuccessBounds.Width);
171-
float successBoundsMiddleY = Globals.MiddleY(SuccessBounds.Y, SuccessBounds.Height);
172-
173120
Parallel.ForEach(generatedStep.Creatures, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, creature =>
174121
{
175122
if (!creature.IsDead || creature == BestCreature || creature == SelectedCreature)
@@ -262,17 +209,7 @@ public virtual void NextStep(bool gatherInfoForAllCreatures = false)
262209

263210
//Identify the best creature in the step.
264211

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)
276213
{
277214
newBestCreature = creature;
278215
}

MaceEvolve.Mono.Desktop/Game1.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected override void Initialize()
7676
MainGameHost = new GraphicalGameHost<GraphicalStep<GraphicalCreature, GraphicalFood>, GraphicalCreature, GraphicalFood>();
7777
MainGameHost.CreatureSize = 5;
7878
MainGameHost.FoodSize = MainGameHost.CreatureSize * 0.7f;
79-
MainGameHost.CreatureSpeed = MainGameHost.UseSuccessBounds ? 2.75f * 1.3f : 2.75f;
79+
MainGameHost.CreatureSpeed = 2.75f;
8080

8181
Reset();
8282

@@ -159,11 +159,6 @@ protected override void Draw(GameTime gameTime)
159159
_spriteBatch.DrawCircle(food.MX, food.MY, food.Size, 18, food.Color, food.Size);
160160
}
161161

162-
if (MainGameHost.UseSuccessBounds)
163-
{
164-
_spriteBatch.DrawRectangle(MainGameHost.SuccessBounds.X, MainGameHost.SuccessBounds.Y, MainGameHost.SuccessBounds.Width, MainGameHost.SuccessBounds.Height, new Color(Color.Green, 100));
165-
}
166-
167162
if (SimulationRunning)
168163
{
169164
_spriteBatch.DrawString(BigUIFont, IsInFastMode ? "Running (Fast)" : "Running", new Vector2(10, 15), Color.White);
@@ -232,11 +227,6 @@ public void Reset()
232227
Rectangle gameBounds = _graphics.GraphicsDevice.PresentationParameters.Bounds;
233228
MainGameHost.WorldBounds = new Core.Models.Rectangle(gameBounds.X, gameBounds.Y, gameBounds.Width, gameBounds.Height);
234229

235-
float MiddleWorldBoundsX = Globals.MiddleX(MainGameHost.WorldBounds.X, MainGameHost.WorldBounds.Width);
236-
float MiddleWorldBoundsY = Globals.MiddleX(MainGameHost.WorldBounds.Y, MainGameHost.WorldBounds.Height);
237-
238-
MainGameHost.SuccessBounds = new Core.Models.Rectangle(MiddleWorldBoundsX - 75, MiddleWorldBoundsY - 75, 150, 150);
239-
240230
MainGameHost.ResetStep(GenerateCreatures(), GenerateFood());
241231

242232
FailedRunsUptimes.Clear();

MaceEvolve.WinForms/MainForm.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ public void Reset()
4949
{
5050
MainGameHost.WorldBounds = new Core.Models.Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
5151

52-
float MiddleWorldBoundsX = Globals.MiddleX(MainGameHost.WorldBounds.X, MainGameHost.WorldBounds.Width);
53-
float MiddleWorldBoundsY = Globals.MiddleX(MainGameHost.WorldBounds.Y, MainGameHost.WorldBounds.Height);
54-
55-
MainGameHost.SuccessBounds = new Core.Models.Rectangle(MiddleWorldBoundsX - 75, MiddleWorldBoundsY - 75, 150, 150);
56-
5752
BestCreatureNetworkViewerForm.NetworkViewer.Step = null;
5853
BestCreatureNetworkViewerForm.NetworkViewer.NeuralNetwork = null;
5954

@@ -218,11 +213,6 @@ private void MainForm_Paint(object sender, PaintEventArgs e)
218213
e.Graphics.FillEllipse(brush, food.X, food.Y, food.Size, food.Size);
219214
}
220215
}
221-
222-
if (MainGameHost.UseSuccessBounds)
223-
{
224-
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Green)), new System.Drawing.Rectangle((int)MainGameHost.SuccessBounds.X, (int)MainGameHost.SuccessBounds.Y, (int)MainGameHost.SuccessBounds.Width, (int)MainGameHost.SuccessBounds.Height));
225-
}
226216
}
227217
private void MainForm_MouseClick(object sender, MouseEventArgs e)
228218
{
@@ -269,7 +259,7 @@ private void MainForm_Load(object sender, EventArgs e)
269259
MainGameHost = new GraphicalGameHost<GraphicalStep<GraphicalCreature, GraphicalFood>, GraphicalCreature, GraphicalFood>();
270260
MainGameHost.CreatureSize = 10;
271261
MainGameHost.FoodSize = MainGameHost.CreatureSize * 0.7f;
272-
MainGameHost.CreatureSpeed = MainGameHost.UseSuccessBounds ? 2.75f * 1.3f : 2.75f;
262+
MainGameHost.CreatureSpeed = 2.75f;
273263

274264
MainGameHost.BestCreatureChanged += MainGameHost_BestCreatureChanged;
275265
MainGameHost.SelectedCreatureChanged += MainGameHost_SelectedCreatureChanged;

0 commit comments

Comments
 (0)