Пример #1
0
    //public AlgorithmEvaluator(AlgorithmExecutor executor, ICollection<ITest> tests, IAnswerEvaluator answerEvaluator, TimeSpan timeLimit) : this(tests, answerEvaluator, timeLimit)
    //{
    //    this.executor = executor;
    //}
    //public AlgorithmEvaluator(string algorithmFolder, ICollection<ITest> tests, IAnswerEvaluator answerEvaluator, TimeSpan timeLimit)
    //    : this(new AlgorithmExecutor(algorithmFolder), tests, answerEvaluator, timeLimit)
    //{
    //}
    //public void SetAlgorithm(AlgorithmExecutor newAlg)
    //{
    //    this.executor = newAlg;
    //}
    public int EvaluateWithTest(AlgorithmExecutor algorithm, ITest test, bool allowTimeLimit = false)
    {
        this.logWriter.WriteLine();
        this.logWriter.WriteLine("Evaluating {0} with test {1}", algorithm.AlgorithmOwner, test.Name);

        try
        {
            algorithm.StartAlgorithm();
        }
        catch (Win32Exception)
        {
            this.logWriter.WriteLine("--couldn't start algorithm");
            return 0;
        }

        DateTime start = DateTime.Now;

        string algorithmAnswer = "";
        try
        {
            Task<string> algorithmAnswerTask = Task.Run(() => algorithm.GetAnswerToInput(test.Input));

            bool timeLimitReached = false;
            //Console.WriteLine("press enter");
            //Console.ReadLine();
            System.Threading.Thread.Sleep(timeLimit - TimeSpan.FromMilliseconds(100));
            while (!algorithmAnswerTask.IsCompleted)
            {
                TimeSpan elapsed = DateTime.Now - start;
                if (elapsed > timeLimit)
                {
                    this.logWriter.WriteLine("--time limit reached, killing algorithm");
                    algorithm.KillAlgorithm();
                    timeLimitReached = true;
                    break;
                }
            }

            if (!timeLimitReached || allowTimeLimit)
            {
                this.logWriter.WriteLine("--attempting to retrieve output from algorithm");
                algorithmAnswerTask.Wait();
                algorithmAnswer += algorithmAnswerTask.Result;
            }
            else
            {
                return 0;
            }

            algorithm.KillAlgorithm(); //just in case
        }
        catch (Exception e)
        {
            this.logWriter.WriteLine("--unexpected error while evaluating: {0}", e.Message);
        }

        this.logWriter.Write("--algorithm output:\r\n{0}\r\n", algorithmAnswer);
        return this.evaluator.EvaluateAnswer(algorithmAnswer, test.Input, test.ExpectedOutput);
    }
Пример #2
0
 public Player(AlgorithmExecutor algorithm, Circle body)
 {
     this.algorithm = algorithm;
     this.name = algorithm.AlgorithmOwner;
     this.body = body;
     this.isAlive = true;
     this.reloadTimeRemaining = 0;
     this.bullets = new List<Bullet>();
 }
Пример #3
0
    public int EvaluateWithAllTests(AlgorithmExecutor algorithm, bool allowTimeLimit = false)
    {
        if (algorithm == null)
        {
            throw new InvalidOperationException("No algorithm is set");
        }

        int total = 0;

        foreach (var currTest in this.tests)
        {
            total += this.EvaluateWithTest(algorithm, currTest, allowTimeLimit);
        }

        return total;
    }
Пример #4
0
        private static void LoadPlayers()
        {
            string[] algDirs = System.IO.Directory.GetDirectories("algorithms");

            AlgorithmExecutor firstPlayerAlgorithm = new AlgorithmExecutor(algDirs[0]);
            AlgorithmExecutor secondPlayerAlgorithm = new AlgorithmExecutor(algDirs[1]);

            firstPlayer = new Player(firstPlayerAlgorithm, new Circle(new Vector2(firstPlayerBodyX, 0), playerBodyRadius));
            secondPlayer = new Player(secondPlayerAlgorithm, new Circle(new Vector2(secondPlayerBodyX, 0), playerBodyRadius));

            firstPlayerCommandEvaluator = new PlayerCommandEvaluator(firstPlayer);
            secondPlayerCommandEvaluator = new PlayerCommandEvaluator(secondPlayer);
        }
Пример #5
0
 public void ContinueOrPauseAlgorithm()
 {
     AlgorithmExecutor.ContinueOrPause();
 }
Пример #6
0
 public void StopAlgorithm()
 {
     AlgorithmExecutor.Stop(false);
     IsAlgorithmRun = false;
     IsAlgorithmControlPanelEnabled = false;
 }
Пример #7
0
 public void AlgorithmStepBack()
 {
     AlgorithmExecutor.StepBack();
 }
Пример #8
0
 public void AlgorithmStepNext()
 {
     AlgorithmExecutor.StepNext();
 }
Пример #9
0
 public void RestartAlgorithm()
 {
     AlgorithmExecutor.Restart();
 }