public B_Brain(int inputCount, int outputCount, int numberOfIntermediateLayers, int intermediateLayerCount) { int nid = 0; Neurons = new B_Neuron[numberOfIntermediateLayers + 2][]; Neurons[0] = new B_Neuron[inputCount]; for (int i = 0; i < inputCount; i++) { Neurons[0][i] = new B_Neuron(nid++); } for (int layer = 0; layer < numberOfIntermediateLayers; layer++) { Neurons[layer + 1] = new B_Neuron[intermediateLayerCount]; for (int i = 0; i < intermediateLayerCount; i++) { Neurons[layer + 1][i] = new B_Neuron(nid++); } } Neurons[numberOfIntermediateLayers + 1] = new B_Neuron[outputCount]; for (int i = 0; i < outputCount; i++) { Neurons[numberOfIntermediateLayers + 1][i] = new B_Neuron(nid++); } for (int layer = 1; layer < Neurons.Length; layer++) { for (int i = 0; i < Neurons[layer - 1].Length; i++) { for (int j = 0; j < Neurons[layer].Length; j++) { Neurons[layer][j].AddConnection(Neurons[layer - 1][i], GlobalRandom.NextBetween(-1, 1)); } } } M_NeuronID = nid; }
public void SpawnReset(GameTimer timer) { fallingItems.Add(new LunchItem(new Vector2((float)GlobalRandom.NextBetween(0, Settings.GP_X - LunchItem.Width), -LunchItem.Height), GlobalRandom.RandomFrom(Goodies))); if (keepSpawning) { GameTimer.AddStaticTimer(Last, new TimeSpan(0, 0, 0, 0, GlobalRandom.random.Next(MAX_TIME - MIN_TIME) + MIN_TIME), SpawnReset); } }
public void Mutate(double cAdjust, int mCV) { int tgt = GlobalRandom.random.Next(M_NeuronID); B_Neuron target = getNeuron(tgt); if (target.connections.Count > 0) { B_Connection adjc = target.connections[GlobalRandom.random.Next(target.connections.Count)]; adjc.Weight += GlobalRandom.NextBetween(-cAdjust, cAdjust); adjc.Weight = MathHelper.Clamp((float)adjc.Weight, -mCV, mCV); } }
public void Mutate(double aeAdjust, double elAdjust, double cAdjust, int mCV) { PulseNeuron target = getNeuron(GlobalRandom.random.Next(M_NeuronID)); target.ActivationEnergy += GlobalRandom.NextBetween(-aeAdjust, aeAdjust); if (target.ActivationEnergy < 0) { target.ActivationEnergy = 0; } target.EnergyDecay += GlobalRandom.NextBetween(-elAdjust, elAdjust); if (target.EnergyDecay < 0) { target.EnergyDecay = 0; } if (target.connections.Count > 0) { Connection adjc = target.connections[GlobalRandom.random.Next(target.connections.Count)]; adjc.amt += GlobalRandom.NextBetween(-cAdjust, cAdjust); adjc.amt = MathHelper.Clamp((float)adjc.amt, -mCV, mCV); } }
public PulseBrain(int inputCount, int outputCount, int numberOfIntermediateLayers, int intermediateLayerCount) { int Nextid = 0; Inputs = new List <PulseNeuron>(inputCount); for (int i = 0; i < inputCount; i++) { Inputs.Add(new PulseNeuron(GlobalRandom.NextBetween(0, 1), GlobalRandom.NextBetween(0, 1), Nextid++)); } noninputs = new List <List <PulseNeuron> >(1 + numberOfIntermediateLayers); for (int intermed = 0; intermed < numberOfIntermediateLayers; intermed++) { noninputs.Add(new List <PulseNeuron>(intermediateLayerCount)); for (int i = 0; i < intermediateLayerCount; i++) { noninputs[intermed].Add(new PulseNeuron(GlobalRandom.NextBetween(0, 1), GlobalRandom.NextBetween(0, 1), Nextid++)); } } noninputs.Add(new List <PulseNeuron>(outputCount)); for (int i = 0; i < outputCount; i++) { noninputs[numberOfIntermediateLayers].Add(new PulseNeuron(GlobalRandom.NextBetween(0, 1), GlobalRandom.NextBetween(0, 1), Nextid++)); } List <PulseNeuron> prevlayer = Inputs; for (int i = 0; i < noninputs.Count; i++) { for (int from = 0; from < prevlayer.Count; from++) { for (int to = 0; to < noninputs[i].Count; to++) { prevlayer[from].AddConnection(noninputs[i][to], GlobalRandom.NextBetween(0, 1)); } } prevlayer = noninputs[i]; } M_NeuronID = Nextid; }
public override void RunAI(Player p, Difficulty difficulty) { foreach (Pipe pipe in pipes) { if (!p.isP1) { if (pipe.getPlayer() == p) { // Time between light entering range and pressing the button TimeSpan Reaction; // Time between pressing the button and releasing it TimeSpan Release; // Extra wait time before pressing button (for fast shots) int HitBuffer; switch (difficulty) { case Difficulty.SEasy: // Super Easy Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(750, 1500)); Release = new TimeSpan(0, 0, 0, 3, 0); HitBuffer = 0; break; case Difficulty.Easy: // Easy Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(600, 900)); Release = new TimeSpan(0, 0, 0, 1, 0); HitBuffer = 0; break; default: case Difficulty.Medium: // Medium Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(300, 600)); Release = new TimeSpan(0, 0, 0, 0, 50); HitBuffer = 0; break; case Difficulty.Hard: // Hard Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(100, 600)); Release = new TimeSpan(0, 0, 0, 0, 50); HitBuffer = 50; break; case Difficulty.SHard: // Super Hard Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(100, 400)); Release = new TimeSpan(0, 0, 0, 0, 30); HitBuffer = 150; break; } if (!AI_pending.Contains(pipe.getButton()) && pipe.getlightBox().Y - (pipe.getUpEndBox().Y + pipe.getUpEndBox().Height) <= pipe.getUpHitBox().Height - HitBuffer) { ControllerButton pbtn = pipe.getButton(); AI_pending.Add(pbtn); GameTimer.AddStaticTimer(Settings.UPDATE_GT, Reaction, x => { AI_pending.Remove(pbtn); p.GamePad.GetSimState().SetButtonDown(pbtn); GameTimer.AddStaticTimer(Settings.UPDATE_GT, Release, y => { p.GamePad.GetSimState().SetButtonUp(pbtn); }); }); } } } else { // Time between light entering range and pressing the button TimeSpan Reaction; // Time between pressing the button and releasing it TimeSpan Release; // Extra wait time before pressing button (for fast shots) int HitBuffer; switch (difficulty) { case Difficulty.SEasy: // Super Easy Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(750, 1500)); Release = new TimeSpan(0, 0, 0, 3, 0); HitBuffer = (int)GlobalRandom.NextBetween(0, 150); break; case Difficulty.Easy: // Easy Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(600, 900)); Release = new TimeSpan(0, 0, 0, 1, 0); HitBuffer = (int)GlobalRandom.NextBetween(0, 150); break; default: case Difficulty.Medium: // Medium Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(300, 600)); Release = new TimeSpan(0, 0, 0, 0, 50); HitBuffer = (int)GlobalRandom.NextBetween(0, 200); break; case Difficulty.Hard: // Hard Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(100, 600)); Release = new TimeSpan(0, 0, 0, 0, 50); HitBuffer = (int)GlobalRandom.NextBetween(50, 200); break; case Difficulty.SHard: // Super Hard Reaction = new TimeSpan(0, 0, 0, 0, (int)GlobalRandom.NextBetween(100, 400)); Release = new TimeSpan(0, 0, 0, 0, 30); HitBuffer = 150; break; } if (!AI_pending_1.Contains(pipe.getButton()) && (pipe.getDownEndBox().Y) - (pipe.getlightBox().Y + pipe.getlightBox().Height) <= pipe.getDownHitBox().Height - HitBuffer) { ControllerButton pbtn = pipe.getButton(); AI_pending_1.Add(pbtn); GameTimer.AddStaticTimer(Settings.UPDATE_GT, Reaction, x => { AI_pending_1.Remove(pbtn); p.GamePad.GetSimState().SetButtonDown(pbtn); GameTimer.AddStaticTimer(Settings.UPDATE_GT, Release, y => { p.GamePad.GetSimState().SetButtonUp(pbtn); }); }); } } } }