Beispiel #1
0
 public CommandFactory(MapImplementation map)
 {
     commands = new Dictionary <Type, ICommand> {
         [typeof(MakeStep)]  = new MakeStep(map),
         [typeof(TakeStuff)] = new TakeStuff(map),
         [typeof(LookAt)]    = new LookAt(map),
         [typeof(Turn)]      = new Turn(map),
         [typeof(GoTo)]      = new GoTo(map),
     };
 }
        public void Start()
        {
            Bot[] winners = null;
            int   counter = 0;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            while (LOOP_COUNT > counter++)
            {
                var map = new MapImplementation();
                map.CreateAndFillWorldObjects();
                map.Add(EventController.Instance);

                var commandFactory = new CommandFactory(map);

                var botFactory = new BotFactory(commandFactory);

                Bot[] bots = botFactory.CreateBots(winners);

                map.Add(bots);

                var executionContext = new Context(map, bots);

                executionContext.Run();

                winners = executionContext.GetWinners();
                if (counter % 500 == 0)
                {
                    sw.Stop();

                    Console.WriteLine($"{LOOP_COUNT}/{LOOP_COUNT - counter} iterations...");
                    PrintGenerations(winners);
                    Console.WriteLine($"Elapsed time: {sw.Elapsed.ToString(@"hh\:mm\:ss")}");
                    WriteStatisticToStorage(counter.ToString());

                    sw.Restart();
                }

                statistics.AddRange(bots.Select(x => new Statistics {
                    Generation = x.Generation,
                    Iteration  = counter,
                    StepCount  = x.StepCounter
                }));

                IncrementGeneration(winners);
                ResetStates(winners);
            }
            WriteStatisticToStorage("final");
        }
 public GoTo(MapImplementation map)
 {
     this.map = map;
 }
 public LookAt(MapImplementation map)
 {
     this.map = map;
 }
 public TakeStuff(MapImplementation map)
 {
     this.map = map;
 }
 public MakeStep(MapImplementation map)
 {
     this.map = map;
 }
Beispiel #7
0
 public Context(MapImplementation map, Bot[] bots)
 {
     this.map  = map;
     this.bots = bots;
 }
Beispiel #8
0
 public Turn(MapImplementation map)
 {
     this.map = map;
 }