The prey capture task's grid world. Encapsulates agent's sensor and motor hardware and the prey's simple stochastic movement.
        /// <summary>
        /// Construct the view with an appropriately configured world and a genome decoder for decoding genomes as they are passed into RefreshView().
        /// </summary>
        public PreyCaptureView(IGenomeDecoder<NeatGenome,IBlackBox> genomeDecoder, PreyCaptureWorld world)
        {
            try
            {
                InitializeComponent();

                _genomeDecoder = genomeDecoder;
                _world = world;
                
                // Create a bitmap for the picturebox.
                int width = Width;
                int height = Height;
                _image = new Bitmap(width, height, ViewportPixelFormat);           
                pbx.Image = _image;

                // Create background thread for running simulation alongside NEAT algorithm.
                _simThread = new Thread(new ThreadStart(SimulationThread));
                _simThread.IsBackground = true;
                _simThread.Start();
            }
            finally
            {
                _initializing = false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Construct the view with an appropriately configured world and a genome decoder for decoding genomes as they are passed into RefreshView().
        /// </summary>
        public PreyCaptureView(IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder, PreyCaptureWorld world)
        {
            try
            {
                InitializeComponent();

                _genomeDecoder = genomeDecoder;
                _world         = world;

                // Create a bitmap for the picturebox.
                int width  = Width;
                int height = Height;
                _image    = new Bitmap(width, height, ViewportPixelFormat);
                pbx.Image = _image;

                // Create background thread for running simulation alongside NEAT algorithm.
                _simThread = new Thread(new ThreadStart(SimulationThread));
                _simThread.IsBackground = true;
                _simThread.Start();
            }
            finally
            {
                _initializing = false;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Evaluate the provided IBlackBox against the XOR problem domain and return its fitness score.
        /// </summary>
        public FitnessInfo Evaluate(IBlackBox box)
        {
            // Create grid based world.
            PreyCaptureWorld world = new PreyCaptureWorld(_gridSize, _preyInitMoves, _preySpeed, _sensorRange, _maxTimesteps);

            // Perform multiple independent trials.
            int fitness = 0;

            for (int i = 0; i < _trialsPerEvaluation; i++)
            {
                // Run trial and count how many trials end with the agent catching the prey.
                if (world.RunTrial(box))
                {
                    fitness++;
                }
            }

            // Track number of evaulations and test stop condition.
            _evalCount++;
            if (fitness == _trialsPerEvaluation)
            {
                _stopConditionSatisfied = true;
            }

            // return fitness score.
            return(new FitnessInfo(fitness, fitness));
        }