Esempio n. 1
0
        public void BuildLandscapeGrid(bool buildWithRandomObstacles)
        {
            _rover.gridCoordinates = new List<Coordinates>();

            for (int i = 0; i <= _rover._landscapeWidth; i++)
            {
                for (int ii = 0; ii <= _rover._landscapeHeight; ii++)
                {
                    Coordinates crd = new Coordinates();
                    crd.xCoordinate = i;
                    crd.yCoordinate = ii;
                    //for now set random obstacles
                    if (buildWithRandomObstacles)
                    {
                        Random random = new Random();
                        if (random.Next(11) > 4)
                        {
                            crd.containsObstacle = true;
                        }
                        else
                        {
                            crd.containsObstacle = false;
                        }
                    }
                    else
                    {
                        crd.containsObstacle = false;
                    }

                    _rover.gridCoordinates.Add(crd);
                }
            }

            //make sure there is at least one obstacle if set to random
            if(buildWithRandomObstacles)
            {
                Coordinates _setCoordinate = new Coordinates
                {
                    xCoordinate = 1,
                    yCoordinate = 0,
                    containsObstacle = true
                };
                Coordinates coor = (from Coordinates in _rover.gridCoordinates
                                    where Coordinates.xCoordinate == 1 && Coordinates.yCoordinate == 0
                                    select Coordinates).FirstOrDefault<Coordinates>();
                int indexOf = -1;
                if (coor != null)
                {
                    indexOf = _rover.gridCoordinates.IndexOf(coor);
                }
                if(indexOf >= 0)
                {
                    _rover.gridCoordinates[indexOf].containsObstacle = true;
                }
            }
        }
Esempio n. 2
0
        public void Test_For_Obstacle_Detection()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            Navigation navigation = new Navigation(rover);
            string headingIndex = navigation.GetDirectionalHeading();
            rover.PositionY = 0;
            rover.PositionX = 0;

            rover.LandscapeHeight = 5;
            rover.LandscapeWidth = 5;
            Landscape landscape = new Landscape(rover);
            landscape.BuildLandscapeGrid(false);

            //set obstacle
            Coordinates crd = new Coordinates{

                 xCoordinate = 1,
                 yCoordinate =0
            };
            Coordinates coor = (from Coordinates in rover.gridCoordinates
                                where Coordinates.xCoordinate == 1 && Coordinates.yCoordinate == 0
                                select Coordinates).FirstOrDefault<Coordinates>();
            bool notNull = coor != null;
            int indexOf = -1;
            if(coor != null)
            {
                indexOf = rover.gridCoordinates.IndexOf(coor);
            }

            //int indexOf = rover.gridCoordinates.IndexOf(crd);
            bool hasIndex = indexOf > 0;
            if (hasIndex)
            {
                rover.gridCoordinates[indexOf].containsObstacle = true;
            }

            string rtnMessage = "";
            char[] cmds = ("f").ToCharArray();
            while (!rover.ReportObstacle)
            {
                foreach (char c in cmds)
                {
                    rtnMessage = rover.Command_Parser(c.ToString());
                }
                //break;
            }

            Assert.AreEqual(true, rtnMessage.Contains("Obst"));
        }