diff --git a/src/Common/ExtendedColor.cs b/src/Common/ExtendedColor.cs index 2c81550..91493b9 100644 --- a/src/Common/ExtendedColor.cs +++ b/src/Common/ExtendedColor.cs @@ -49,7 +49,7 @@ public void SetColor(Color color) { } public Color ToColor() { - return Color.FromArgb(R, G, B); + return Color.FromArgb(32, Color.FromArgb(R, G, B)); } } diff --git a/src/Neat/Calculation/Calculator.cs b/src/Neat/Calculation/Calculator.cs index 263193a..71a75bc 100644 --- a/src/Neat/Calculation/Calculator.cs +++ b/src/Neat/Calculation/Calculator.cs @@ -62,8 +62,7 @@ public IList Calculate(ExtendedColorWrapper[] inputs) { // Insert the input values to the Calculator's input nodes. for (int i = 0; i < InputNodes.Count; i++) { - Color inputColor = inputs[i].ExtendedColor.ToColor(); - InputNodes[i].Output = inputColor.GetBrightness(); + InputNodes[i].Output = inputs[i].ExtendedColor.Double; } // Begin calculations. diff --git a/src/Neat/Genetic/Genome.cs b/src/Neat/Genetic/Genome.cs index 963ff2b..c394d16 100644 --- a/src/Neat/Genetic/Genome.cs +++ b/src/Neat/Genetic/Genome.cs @@ -36,8 +36,20 @@ public void Mutate() { } public void MutateActivationRandom() { - NodeGene? node = Nodes.GetRandomElement(); - if (node?.X > 0.1) { + if (!Nodes.Any()) { + return; + } + int retry = 0; + NodeGene node; + do { + retry++; + node = Nodes.GetRandomElement(); + } while (node == null && retry < 5); + if (node == null) { + // Give up. + return; + } + if (node.X > 0.1) { ActivationEnumeration a = ActivationEnumeration.GetRandom(); node.Activation = a.Activation; } @@ -64,9 +76,19 @@ public void MutateLink() { } public void MutateNode() { - ConnectionGene connection = Connections.GetRandomElement()!; - if (connection == null) + if (!Connections.Any()) { + return; + } + int retry = 0; + ConnectionGene connection; + do { + retry++; + connection = Connections.GetRandomElement()!; + } while (connection == null && retry < 5); + if (connection == null) { + // Give up. return; + } NodeGene from = connection.In; NodeGene to = connection.Out; @@ -96,14 +118,30 @@ public void MutateNode() { } public void MutateToggleLink() { - ConnectionGene connection = Connections.GetRandomElement()!; + if (!Connections.Any()) { + return; + } + ConnectionGene connection; + int retry = 0; + do { + retry++; + connection = Connections.GetRandomElement()!; + } while (connection == null && retry < 5); if (connection != null) { connection.Enabled = !connection.Enabled; } } public void MutateWeightRandom() { - ConnectionGene connection = Connections.GetRandomElement()!; + if (!Connections.Any()) { + return; + } + ConnectionGene connection; + int retry = 0; + do { + retry++; + connection = Connections.GetRandomElement()!; + } while (connection == null && retry < 5); if (connection != null) { connection.Weight = ThreadSafeRandom.GetNormalizedRandom(0, 0.2f) * GenomeConstants.WEIGHT_RANDOM_STRENGTH; } diff --git a/src/Neat/Genetic/GenomeConstants.cs b/src/Neat/Genetic/GenomeConstants.cs index ca72a7e..dacf0e6 100644 --- a/src/Neat/Genetic/GenomeConstants.cs +++ b/src/Neat/Genetic/GenomeConstants.cs @@ -10,16 +10,16 @@ internal sealed class GenomeConstants { public static readonly double WEIGHT_SHIFT_STRENGTH = 0.3; // Weight random strength - public static readonly double WEIGHT_RANDOM_STRENGTH = 0.03; + public static readonly double WEIGHT_RANDOM_STRENGTH = 0.13; // Probability to add a connection - public static readonly double PROBABILITY_MUTATE_LINK = 0.03; + public static readonly double PROBABILITY_MUTATE_LINK = 0.12; // Probability to add a node - public static readonly double PROBABILITY_MUTATE_NODE = 0.03; + public static readonly double PROBABILITY_MUTATE_NODE = 0.05; // Probability to shift a weight - public static readonly double PROBABILITY_MUTATE_WEIGHT_SHIFT = 0.02; + public static readonly double PROBABILITY_MUTATE_WEIGHT_SHIFT = 0.12; // Probability to change a weight public static readonly double PROBABILITY_MUTATE_WEIGHT_RANDOM = 0.02; diff --git a/src/Rendering/BatchRenderer.cs b/src/Rendering/BatchRenderer.cs index 85e0016..2f3f542 100644 --- a/src/Rendering/BatchRenderer.cs +++ b/src/Rendering/BatchRenderer.cs @@ -97,15 +97,22 @@ public void RenderInputRegion() { if (!this.owner.UseNeat || this.gui == null) { return; } - int x = IsBotting ? this.owner._inputX : (int) this.owner.InputRegionX.Value; - int y = IsBotting ? this.owner._inputY : (int) this.owner.InputRegionY.Value; - int width = IsBotting ? this.owner._inputWidth : (int) this.owner.InputRegionWidth.Value; - int height = IsBotting ? this.owner._inputHeight : (int) this.owner.InputRegionHeight.Value; - Color inputRegionColor = Color.FromArgb(32, Color.DarkGray); - this.gui.DrawBox(x, y, x + width, y + height, null, inputRegionColor, DisplaySurfaceID.EmuCore); + Color inputOutlineColor = Color.FromArgb(72, Color.Yellow); + Color inputRegionColor = Color.FromArgb(32, Color.Yellow); + int x = (int) this.owner.InputRegionX.Value; + int y = (int) this.owner.InputRegionY.Value; + int width = (int) this.owner.InputRegionWidth.Value; + int height = (int) this.owner.InputRegionHeight.Value; + this.gui.DrawBox(x, y, x + width, y + height, inputOutlineColor, inputRegionColor, DisplaySurfaceID.EmuCore); + if (this.IsBotting) { + Color blockOutlineColor = Color.FromArgb(48, Color.AliceBlue); + int radius = this.owner._inputSampleSize / 2; foreach (ExtendedColorWrapper block in this.owner._neatInputRegionData) { - this.gui.DrawBox(block.X - block.Radius, block.Y - block.Radius, block.X + block.Radius, block.Y + block.Radius, null, block.ExtendedColor.ToColor(), DisplaySurfaceID.EmuCore); + Color blockColor = block.ExtendedColor.ToColor(); + int x1 = (block.X * this.owner._inputSampleSize) + radius + this.owner._inputX; + int y1 = (block.Y * this.owner._inputSampleSize) + radius + this.owner._inputY; + this.gui.DrawBox(x1 - radius, y1 - radius, x1 + radius, y1 + radius, blockOutlineColor, blockColor, DisplaySurfaceID.EmuCore); } } }