Exemplo n.º 1
0
        public FitnessInfo Evaluate(IBlackBox phenome)
        {
            SimpleSnakeWorld sw = new SimpleSnakeWorld(_swparams);

            sw.Init();
            SnakeRunnerSmart sr = new SnakeRunnerSmart(sw, phenome, _inputMapper, _outputMapper, 0, _maxTicksWithoutEating);

            //SimpleSnakeWorld clone = _srf.GetWorldClone();
            //clone.Init();
            //SnakeRunner sr = new SnakeRunnerWxH(clone, phenome, 0, _maxTicksWithoutScoreChange);


            int    totalSquaredScore           = 0;
            int    totalScore                  = 0;
            int    totalTicks                  = 0;
            double inverseOfMediumFoodDistance = 0;

            _wins = 0;
            int cutoffs = 0;

            for (int runs = 0; runs < _trialsPerEvaluation; runs++)
            {
                sr.RunTrial(runs);
                totalSquaredScore += sr.Score * sr.Score; //was totalScore += sr.Score; changed to emphasize large scores over lower scores
                totalScore        += sr.Score;
                totalTicks        += sr.Ticks;
                //inverseOfMediumFoodDistance += sr.Score / (double) sr.TotalFoodDistance;
                if (sr.Win)
                {
                    _wins++;
                }
                //if (sr.Cutoff)
                //    cutoffs++;
            }

            EvaluationCount++;
            return(new FitnessInfo(totalScore, totalSquaredScore)); //probably a good one
            //return new FitnessInfo(totalSquaredScore, totalScore);
            //return new FitnessInfo(totalScore, Double.MaxValue/(totalSquaredScore+1));
            //return new FitnessInfo(totalScore, Double.MaxValue / (totalSquaredScore - totalScore + 1)); //probably a good one
            //TODO: magari cambiare la fitness...
            //return new FitnessInfo((double)(totalSquaredScore + totalScore*totalScore)/1024, totalScore);
            //return new FitnessInfo(phenome.GetHashCode(), phenome.GetHashCode()); //prova
        }
Exemplo n.º 2
0
 private void SimulationThread()
 {
     try
     {
         // Wait for first agent to be passed in.
         _simStartEvent.WaitOne();
         while (!_stopThread)
         {
             try
             {
                 _snakeRunner.Phenome = _box;
                 _snakeRunner.RunTrial();
             }
             finally
             {   // Simulation completed. Reset _simRunningFlag to allow another simulation to be started.
                 Interlocked.Exchange(ref _simRunningFlag, 0);
             }
         }
     }
     catch (ThreadAbortException)
     {   // Thread abort exceptions are expected.
     }
 }