Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #3
0
        public double Distance(RadialPosition rp)
        {
            double x_1 = rp.radius * Math.Cos(rp.theta);
            double y_1 = rp.radius * Math.Sin(rp.theta);

            double x_2 = this.radius * Math.Cos(this.theta);
            double y_2 = this.radius * Math.Sin(this.theta);

            return(Math.Sqrt(Math.Pow(x_2 - x_1, 2) + Math.Pow(y_2 - y_1, 2)));
        }
Beispiel #4
0
        private void PlaceBlobsUniformly()
        {
            Utils.Shuffle <Blob>(this.blobs);
            int    blobCount = this.blobs.Count;
            double spacing   = (2 * Math.PI) / blobCount;

            for (int i = 0; i < blobCount; i++)
            {
                RadialPosition home = new RadialPosition(1, spacing * (i + 1));
                this.blobs[i].SetPosition(home);
                this.blobs[i].SetHome(home);
            }
        }
Beispiel #5
0
        public void StepTo(RadialPosition rp, double stepSize)
        {
            double x_1 = this.radius * Math.Cos(this.theta);
            double y_1 = this.radius * Math.Sin(this.theta);

            double x_2 = rp.radius * Math.Cos(rp.theta);
            double y_2 = rp.radius * Math.Sin(rp.theta);

            // Calculate the normalized subtraction vector
            double delta_x   = x_2 - x_1;
            double delta_y   = y_2 - y_1;
            double magnitude = Math.Sqrt(Math.Pow(delta_x, 2) + Math.Pow(delta_y, 2));
            double scale     = stepSize / magnitude;

            this.SetNewCoordinates(x_1 + delta_x * scale, y_1 + delta_y * scale);
        }
Beispiel #6
0
        internal List <FoodSite> FindFoodSiteNear(RadialPosition pos, double radius)
        {
            ensureSimulationActive();
            List <FoodSite> food = new List <FoodSite>();

            foreach (FoodSite f in this.food)
            {
                RadialPosition f_pos = f.GetPosition();
                double         dist  = f_pos.Distance(pos);
                if (dist <= radius)
                {
                    food.Add(f);
                }
            }
            return(food);
        }
Beispiel #7
0
        internal List <Blob> FindBlobsNear(RadialPosition pos, double radius)
        {
            ensureSimulationActive();
            List <Blob> blobs = new List <Blob>();

            foreach (Blob b in this.blobs)
            {
                RadialPosition b_pos = b.GetPosition();
                double         dist  = b_pos.Distance(pos);
                if (dist <= radius)
                {
                    blobs.Add(b);
                }
            }
            return(blobs);
        }
Beispiel #8
0
 public RadialPosition(RadialPosition rp)
 {
     this.theta  = rp.theta;
     this.radius = rp.radius;
 }
Beispiel #9
0
 public void SetPosition(RadialPosition position)
 {
     this.position = position;
 }
Beispiel #10
0
 public void SetHome(RadialPosition rp)
 {
     this.home = new RadialPosition(rp);
 }
Beispiel #11
0
 public void SetPosition(RadialPosition rp)
 {
     this.position = new RadialPosition(rp);
 }