Пример #1
0
        static async Task Main(string[] args)
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;

                _cts.Cancel();

                Console.WriteLine("Cancellation requested...");
            };

            //Create the random number generator
            var randomNumberGenerator = new RandomNumberGenerator();

            //Create the world factory
            var worldFactory = new WorldFactory(randomNumberGenerator);

            Entity[] survivingEntities = null;

            for (int generationIndex = 0; generationIndex < 100; generationIndex++)
            {
                Console.WriteLine($"=== Generation {generationIndex} ===");

                var parameters = new WorldCreationParameters
                {
                    ExistingEntities = survivingEntities?
                                       .Select(e => e.Metadata)
                                       .ToArray(),
                    NumberOfEntities     = 1000,
                    NumberOfInstructions = 8
                };

                //Create the world
                var world = worldFactory.Create(parameters);

                Console.WriteLine($"World created. Food location: ({world.WorldState.Food.X}, {world.WorldState.Food.Y})");

                if (_cts.IsCancellationRequested)
                {
                    Console.WriteLine("Cancelled.");

                    return;
                }

                survivingEntities = await ExecuteGenerationAsync(world, _cts.Token);

                //Print out the survivors
                if (survivingEntities != null)
                {
                    foreach (var aliveEntity in survivingEntities)
                    {
                        var distance = aliveEntity.StartLocation.GetDistance(aliveEntity.Location);

                        Console.WriteLine($"  Entity traveled {distance:0.00}: Gen [{aliveEntity.Metadata.Generation}]");
                    }
                }
            }
        }
        public MainWindowViewModel()
        {
            var randomNumberGenerator = new RandomNumberGenerator();

            var parameters = new WorldCreationParameters
            {
                NumberOfEntities = 10
            };

            var factory = new WorldFactory(randomNumberGenerator);

            var world = factory.Create(parameters);

            World = new WorldViewModel(world);

            RunCommand = ReactiveCommand.Create(Run);
        }