예제 #1
0
        private void ComparePerformances(Bot singleThreadBot, Bot multiThreadBot, Rocket initialRocket, int times = 40)
        {
            var successes = 0;
            var stopWatch = new Stopwatch();

            for (var i = 0; i < times; ++i)
            {
                stopWatch.Restart();
                singleThreadBot.GetNextMove(initialRocket);
                stopWatch.Stop();
                var singleThreadBotTime = stopWatch.Elapsed;
                stopWatch.Restart();
                multiThreadBot.GetNextMove(initialRocket);
                stopWatch.Stop();
                var multiThreadBotTime = stopWatch.Elapsed;
                if (multiThreadBotTime < singleThreadBotTime)
                {
                    ++successes;
                }
            }

            Assert.GreaterOrEqual(successes, 0.8 * times,
                                  $"Ваше решение в два потока должно работать быстрее решения в один поток в {times * 0.8} случаев из {times}");
        }
예제 #2
0
 public void Init()
 {
     random  = new Random(223243);
     channel = new Channel <Rocket>();
     rocket  = new Rocket(new Vector(100, 100), Vector.Zero, -0.5 * Math.PI);
 }
예제 #3
0
 public Level(Rocket rocket, Vector[] checkpoints, Physics physics)
 {
     InitialRocket = rocket;
     Checkpoints   = checkpoints;
     Physics       = physics;
 }
예제 #4
0
 private double GetDistanceToNextCheckpoint(Rocket rocket)
 {
     return((rocket.Location - rocket.GetNextRocketCheckpoint(level)).Length);
 }
예제 #5
0
 public Task <Tuple <Turn, double> > GetBestPath(Rocket rocket)
 {
     return(Task.Run(() => SearchBestMove(rocket, new Random(random.Next()), iterationsCount / threadsCount)));
 }