namespace FluffySpoon.Neuro.Evolution.Sample
{classProgram{staticasync Task Main(string[]args){varserviceCollection=new ServiceCollection();
serviceCollection.AddFluffySpoonNeuroEvolution(newEvolutionSettings<CarSimulation>(){AmountOfGenomesInPopulation=100,AmountOfWorstGenomesToRemovePerGeneration=10,//3 input neurons, 4 neurons in 1st hidden layer, 5 neurons in 2nd hidden layer, 2 output neuronsNeuronCounts=new[]{3,4,5,2},SimulationFactoryMethod=()=>new CarSimulation()});varserviceProvider= serviceCollection.BuildServiceProvider();varfirstGeneration= serviceProvider.GetRequiredService<IGeneration<CarSimulation>>();varsecondGeneration=await firstGeneration.EvolveAsync();varthirdGeneration=await secondGeneration.EvolveAsync();//etcvarcarSimulationsOfThirdGeneration= thirdGeneration.Genomes.Select(x => x.Simulation);foreach(var carSimulationOfThirdGeneration in carSimulationsOfThirdGeneration){//render the car simulation or something else.}}}classCarSimulation:ISimulation{enumSteeringType{TurnLeft,DoNothing,TurnRight}enumAccelerationType{Accelerate,DoNothing,Decelerate}publicintDistanceTravelled{get;privateset;}publicdoubleFitness=>-DistanceTravelled;publicboolHasEnded=>DistanceTravelled>10;/// <summary>/// This is called by the learning algorithm to determine the inputs to feed into the neural network./// </summary>/// <returns></returns>publicasyncTask<double[]>GetInputsAsync(){//we simulate that 3 LIDAR sensor readings come in. //the left one reads 100 meters, the middle one reads 80 meters and the right one reads 30 meters. //these will be fed as input neurons.returnnewdouble[]{100,//left sensor input neuron80,//center sensor input neuron30//right sensor input neuron};}/// <summary>/// This is called by the learning algorithm with the neural network's suggestion on what to do based on the input that was given in <see cref="GetInputsAsync"/>./// </summary>publicasync Task TickAsync(double[]outputs){varsteeringType= NeuronInterpretationHelper.InterpretAsEnum<SteeringType>(outputs[0]);varaccelerationType= NeuronInterpretationHelper.InterpretAsEnum<AccelerationType>(outputs[1]);//do something here based on the steering type and acceleration type the neural net suggested.if(accelerationType== AccelerationType.Accelerate)DistanceTravelled++;}publicasync Task ResetAsync(){//reset car positions.}}}