Example #1
0
 public void SetState(Tracker tracker)
 {
     this.x = tracker.X;
     this.y = tracker.Y;
     this.angle = tracker.Angle;
 }
        public void Initialize(Robot robot)
        {
            // Initialize particles
            particles = new List<Particle>(configuration.NumberOfParticles);
            for (int i = 0; i < configuration.NumberOfParticles; i++)
            {
                switch (robot.ExpectedZone)
                {
                    case Robot.Zone.Starting:
                        particles.Add(new Particle(field,
                            configuration.WallMargin + MathHelper.random.NextDouble() * (ObstacleX - 2.0 * configuration.WallMargin),
                            configuration.WallMargin + MathHelper.random.NextDouble() * (FieldHeight - 2.0 * configuration.WallMargin),
                            MathHelper.random.NextDouble() * 360.0));
                        break;
                    case Robot.Zone.Mining:
                        particles.Add(new Particle(field,
                            DigX + configuration.WallMargin + MathHelper.random.NextDouble() * (DigX - 2.0 * configuration.WallMargin),
                            configuration.WallMargin + MathHelper.random.NextDouble() * (FieldHeight - 2.0 * configuration.WallMargin),
                            MathHelper.random.NextDouble() * 360.0));
                        break;
                    case Robot.Zone.Unknown:
                        particles.Add(new Particle(field,
                            configuration.WallMargin + MathHelper.random.NextDouble() * (FieldWidth - 2.0 * configuration.WallMargin),
                            configuration.WallMargin + MathHelper.random.NextDouble() * (FieldHeight - 2.0 * configuration.WallMargin),
                            MathHelper.random.NextDouble() * 360.0));
                        break;
                    default:
                        break;
                }
            }

            // Update tracker
            tracker = new Tracker();
            tracker.FindCenter(particles);
        }