Exemplo n.º 1
0
 public Blob(Blob existingBlob)
 {
     id            = Guid.NewGuid();
     state         = new SearchingState(this);
     this.props    = existingBlob.GetBlobProps();
     this.position = new RadialPosition(existingBlob.GetPosition());
     this.home     = new RadialPosition(existingBlob.GetHome());
     this.satiety  = Satiety.None;
 }
Exemplo n.º 2
0
 public Blob(BlobProps props)
 {
     id            = Guid.NewGuid();
     state         = new SearchingState(this);
     this.props    = props;
     this.position = new RadialPosition();
     this.home     = new RadialPosition();
     this.satiety  = Satiety.None;
 }
Exemplo n.º 3
0
        public async Task Run(int epochs)
        {
            this.mediatorStore = new FoodSiteMediatorStore();
            this.blobs         = new List <Blob>();
            this.food          = new List <FoodSite>();
            int numGreedy    = Convert.ToInt32(this.simulationProps.numBlobs * this.simulationProps.percentageGreedy);
            int numNonGreedy = this.simulationProps.numBlobs - numGreedy;

            for (int i = 0; i < numGreedy; i++)
            {
                BlobProps blobProps = new BlobProps {
                    isGreedy = true,
                    sensor   = new ProximitySensor(this.simulationProps.blobSensorSize),
                    step     = this.simulationProps.blobStepSize,
                };

                this.blobs.Add(new Blob(blobProps));
            }

            for (int i = 0; i < numNonGreedy; i++)
            {
                BlobProps blobProps = new BlobProps {
                    isGreedy = false,
                    sensor   = new ProximitySensor(this.simulationProps.blobSensorSize),
                    step     = this.simulationProps.blobStepSize,
                };

                this.blobs.Add(new Blob(blobProps));
            }

            for (int i = 0; i < epochs; i++)
            {
                int greedyCount    = this.blobs.FindAll((b) => b.GetBlobProps().isGreedy).Count;
                int notGreedyCount = this.blobs.FindAll((b) => !b.GetBlobProps().isGreedy).Count;
                Console.WriteLine(String.Format("Epoch: {0}, GreedyCount: {1}, NotGreedyCount: {2}", i, greedyCount, notGreedyCount));

                this.simulationActive = true;
                // Rehome blobs uniformly across the circle
                this.PlaceBlobsUniformly();
                // Create food and distribute across board
                this.PlaceFoodRandomly(this.simulationProps.numFood);
                // ProcessNext() until all food is eaten and all blobs return home
                while (this.blobs.Exists((blob) => !blob.IsHome()))
                {
                    await this.ProcesIterationStep();
                }
                this.simulationActive = false;
                // Add and remove blobs based on outcomes
                List <Blob> newBlobs = new List <Blob>();
                foreach (Blob b in this.blobs)
                {
                    if (b.GetSatiety() == Satiety.None)
                    {
                        // Dead
                    }
                    else if (b.GetSatiety() == Satiety.Half)
                    {
                        newBlobs.Add(new Blob(b));
                        // Lives
                    }
                    else if (b.GetSatiety() == Satiety.Full)
                    {
                        // Reproduce
                        newBlobs.Add(new Blob(b));
                        newBlobs.Add(new Blob(b));
                    }
                }
                this.blobs = newBlobs;
            }
        }