Ejemplo n.º 1
0
        public virtual void UpdatePositionAndClean(RectangularRoom room, Random random)
        {
            Position newPos = RobotPosition.GetNewPosition(RobotPosition, Direction, Speed);

            if (room.isPositionInRoom(newPos))
            {
                room.cleanTileAtPosition(RobotPosition);
                RobotPosition = newPos;
            }
            else
            {
                Direction = random.Next(360);  //Robotul schimba directia cand se loveste de perete
            }
        }
Ejemplo n.º 2
0
        public void RunSimulation()
        {
            int trial = 0;

            while (trial < NoTrials)
            {
                int timeStep = 0;
                int covarage = 0;
                while (covarage < MinCovarage)
                {
                    for (int i = 0; i < NoRobots; i++)
                    {
                        Robots[i].UpdatePositionAndClean(Room, random);
                    }

                    int     tC  = Room.numCleanedTiles();
                    int     tT  = Room.TilesNo;
                    decimal cov = (decimal)tC / tT * 100;
                    covarage = Convert.ToInt32(cov);
                    Trials[trial].Add(covarage);

                    timeStep++;
                }
                TimeSteps[trial] = timeStep;
                // New room
                Room = new RectangularRoom(Width, Height);
                // New Robots
                Robots = new List <BaseRobot>();
                for (int i = 0; i < NoRobots; i++)
                {
                    Robots.Add(new BaseRobot(Room, Speed, random));
                }

                trial++;
            }
            int totTimeSteps = 0;

            for (int i = 0; i < NoTrials; i++)
            {
                totTimeSteps += TimeSteps[i];
            }
            avarageTimeSteps = totTimeSteps / NoTrials;
        }
Ejemplo n.º 3
0
 public Simulator(int noRobots, int speed, int width, int height, int minCovarage, int noTrails, Visual visualForm)
 {
     random = new Random();
     NoRobots = noRobots;
     Speed = speed;
     Width = width;
     Height = height;
     MinCovarage = minCovarage;
     NoTrials = noTrails;
     Trials = new List<int>[NoTrials];
     for (int i = 0; i < NoTrials; i++)
         Trials[i] = new List<int>();
     TimeSteps = new int[NoTrials];
     Room = new RectangularRoom(Width, Height);
     Robots = new List<BaseRobot>();
     for (int i = 0; i < NoRobots; i++)
         Robots.Add(new BaseRobot(Room, Speed, random));
     this.visualForm = visualForm;
     visualForm.Sim = this;
 }
Ejemplo n.º 4
0
 public Simulator(int noRobots, int speed, int width, int height, int minCovarage, int noTrails, Visual visualForm)
 {
     random      = new Random();
     NoRobots    = noRobots;
     Speed       = speed;
     Width       = width;
     Height      = height;
     MinCovarage = minCovarage;
     NoTrials    = noTrails;
     Trials      = new List <int> [NoTrials];
     for (int i = 0; i < NoTrials; i++)
     {
         Trials[i] = new List <int>();
     }
     TimeSteps = new int[NoTrials];
     Room      = new RectangularRoom(Width, Height);
     Robots    = new List <BaseRobot>();
     for (int i = 0; i < NoRobots; i++)
     {
         Robots.Add(new BaseRobot(Room, Speed, random));
     }
     this.visualForm = visualForm;
     visualForm.Sim  = this;
 }
Ejemplo n.º 5
0
        public void RunSimulation()
        {
            int trial = 0;
            while (trial < NoTrials)
            {
                int timeStep = 0;
                int covarage = 0;
                while (covarage < MinCovarage)
                {
                    for (int i = 0; i < NoRobots; i++)
                        Robots[i].UpdatePositionAndClean(Room, random);

                    int tC = Room.numCleanedTiles();
                    int tT = Room.TilesNo;
                    decimal cov = (decimal)tC / tT * 100;
                    covarage = Convert.ToInt32(cov);
                    Trials[trial].Add(covarage);

                    timeStep++;
                }
                TimeSteps[trial] = timeStep;
                // New room
                Room = new RectangularRoom(Width, Height);
                // New Robots
                Robots = new List<BaseRobot>();
                for (int i = 0; i < NoRobots; i++)
                    Robots.Add(new BaseRobot(Room, Speed, random));

                trial++;
            }
            int totTimeSteps = 0;
            for (int i = 0; i < NoTrials; i++)
                totTimeSteps += TimeSteps[i];
            avarageTimeSteps = totTimeSteps / NoTrials;
        }
Ejemplo n.º 6
0
        }                                // speed is in pixels

        public BaseRobot(RectangularRoom room, int speed, Random random)
        {
            Direction     = random.Next(360);
            this.Speed    = speed;
            RobotPosition = room.randomPosition(random);
        }