コード例 #1
0
 public void Init(SnakeRunnerSmart snakeRunner, IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder)
 {
     _snakeRunner   = snakeRunner;
     _sw            = _snakeRunner.SnakeWorld;
     _genomeDecoder = genomeDecoder;
     this.Size      = new Size((_sw.Width + 2) * _scaleFactor, (_sw.Height + 6) * _scaleFactor);
 }
コード例 #2
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
        }