Skip to content

Commit c7a9a2e

Browse files
committed
Other: Simplify evolution logic.
1 parent ed65c21 commit c7a9a2e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

G33kShell.Desktop/Console/Screensavers/AI/AiGameCanvasBase.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,10 @@ private void TrainAiImpl(Action<byte[]> saveBrainBytes)
9494

9595
// Select the breeders.
9696
var orderedGames = m_games.OrderByDescending(o => o.Rating).ToArray();
97-
var eliteGames = orderedGames.Take((int)(m_currentPopSize * 0.1)).ToArray();
9897

9998
// Report summary of results.
10099
m_generation++;
101-
var veryBest = eliteGames[0];
100+
var veryBest = orderedGames[0];
102101
var stats = $"Gen {m_generation}|Pop {m_currentPopSize}|Rating {veryBest.Rating:F1}|GOAT {m_savedRating:F1}";
103102
var extraStats = veryBest.ExtraGameStats().Select(o => $" {o.Name}: {o.Value}").ToArray().ToCsv().Trim();
104103
if (!string.IsNullOrEmpty(extraStats))
@@ -134,13 +133,10 @@ private void TrainAiImpl(Action<byte[]> saveBrainBytes)
134133

135134
// The GOAT lives on.
136135
if (goatBrain != null)
136+
{
137137
nextBrains.Add(goatBrain.Clone());
138-
139-
// Elite 10% brains get a free pass.
140-
nextBrains.AddRange(eliteGames.Select(o => o.Brain.Clone()));
141-
142-
// ...and 10% more with a small mutation.
143-
nextBrains.AddRange(eliteGames.Select(o => o.Brain.Clone().Mutate(0.02)));
138+
nextBrains.AddRange(Enumerable.Range(0, (int)(m_currentPopSize * 0.05)).Select(_ => goatBrain.Clone().Mutate(0.03)));
139+
}
144140

145141
// Spawn 5% pure randoms.
146142
nextBrains.AddRange(Enumerable.Range(0, (int)(m_currentPopSize * 0.05)).Select(_ => veryBest.Brain.Clone().Randomize()));

0 commit comments

Comments
 (0)