Ejemplo n.º 1
0
        public void Not_Move_To_Occupied_Position()
        {
            // Arrange
            List <RoverRequest> roverInfoReq = new List <RoverRequest>
            {
                new RoverRequest {
                    Name = "Rover1", Instructions = "MM"
                },
                new RoverRequest {
                    Name = "Rover2", Instructions = "MM"
                }
            };


            var sut = new RobotCreator();

            //Act
            var result = sut.CreateAndMoveRobots(roverInfoReq, new int[5, 5]);

            //Assert
            Assert.IsNotNull(result);

            //rover1
            Assert.AreEqual(2, result.First(z => z.Name == "Rover1").NewPositions[0]);
            Assert.AreEqual(0, result.First(z => z.Name == "Rover1").NewPositions[1]);

            //rover2
            Assert.IsTrue(result.First(z => z.Name == "Rover2").Message.ToLower().Contains("occupied by another rover"));
            Assert.AreEqual(1, result.First(z => z.Name == "Rover2").NewPositions[0]);
            Assert.AreEqual(0, result.First(z => z.Name == "Rover2").NewPositions[1]);
        }
Ejemplo n.º 2
0
        void RandomRobot(int posx, int posz, ref int robotCount, ref int weaponCount, ref int createCount, GameObject floder)
        {
            if (createCount % 4 == 0)
            {
                if (gameMap.DeathPlace(posx, posz) && robotCount < DTSKeys.MAX_ROBOT_LIMIT)
                {
                    int robotKey = robotCount;
                    ResourceMgr.Instance.LoadAsync <GameObject>("model/robot/robot_life", (obj) =>
                    {
                        obj.transform.SetParent(floder.transform);
                        obj.name = "robot";
                        obj.transform.position = new Vector3(posx * 10, 10, posz * 10);
                        RobotCreator creator   = obj.GetComponent <RobotCreator>();
                        creator.CreateRobot(robotKey);
                    });
                    robotCount += 1;
                }
            }
            else if (createCount % 4 == 1 && gameMap.DeathPlace(posx, posz) && weaponCount < DTSKeys.MAX_WEAPON_BOX_LIMIT)
            {
                string name = WeaponBoxBase.weaponModelName[weaponCount % WeaponBoxBase.weaponModelName.Count];

                ResourceMgr.Instance.LoadAsync <GameObject>("model/weapon_box/" + name, (obj) =>
                {
                    obj.transform.SetParent(floder.transform);
                    obj.name = "weapon_box";
                    obj.transform.position = new Vector3(posx * 10, 0.5f, posz * 10);
                });
                weaponCount += 1;
            }
        }
    private void OnInspectorUpdate()
    {
        // some methods can only be called from main thread:
        // We check the status to call the methods at the right step in the process:

        Repaint();

        // import Model
        if (status["databaseRefreshed"].WaitOne(0) && !status["importModelDialogShown"].WaitOne(0))
        {
            status["importModelDialogShown"].Set();
            if (EditorUtility.DisplayDialog(
                    "Urdf Assets imported.",
                    "Do you want to generate a " + urdfImporter.robotName + " GameObject now?",
                    "Yes", "No"))
            {
                RobotCreator.Create(Path.Combine(urdfImporter.LocalDirectory, "robot_description.urdf"));
            }
        }

        // refresh Asset Database
        if (status["resourceFilesReceived"].WaitOne(0) && !status["databaseRefreshed"].WaitOne(0))
        {
            status["databaseRefreshStarted"].Set();
            AssetDatabase.Refresh();
            status["databaseRefreshed"].Set();
        }
    }
Ejemplo n.º 4
0
        public void TestRobotCreator()
        {
            rc = new RobotCreator();

            Robot r = rc.Create("");

            bool res = r is CyborgRobot || r is ScienceRobot || r is WorkerRobot;

            Assert.IsTrue(res);
        }
    private static void CreateUrdfObject()
    {
        string urdfFile = EditorUtility.OpenFilePanel("Generate Urdf Model",
                                                      Path.Combine(
                                                          Path.GetDirectoryName(Application.dataPath),
                                                          Path.Combine("Assets", "Urdf")
                                                          ),
                                                      "urdf;*.urdf");

        if (urdfFile != "")
        {
            RobotCreator.Create(urdfFile);
        }
    }
Ejemplo n.º 6
0
        private Robot ChooseRobot(RobotModel model)
        {
            RobotCreator creator      = null;
            double       sum          = 0;
            Random       random       = new Random();
            double       randomNumber = random.NextDouble();

            foreach (KeyValuePair <string, double> probability in ChoiceProbability)
            {
                if (randomNumber <= (sum = sum + probability.Value))
                {
                    creator = ChooseCreator(probability.Key);
                    break;
                }
            }
            return(CreateRobot(model, creator));
        }
Ejemplo n.º 7
0
        public void Return_Positions_For_Given_Rover()
        {
            // Arrange
            List <RoverRequest> roverInfoReq = new List <RoverRequest>
            {
                new RoverRequest {
                    Name = "Rover1", Instructions = "MRM"
                }
            };


            var sut = new RobotCreator();

            //Act
            var result = sut.CreateAndMoveRobots(roverInfoReq, new int[5, 5]);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.First().NewPositions[0]);
            Assert.AreEqual(1, result.First().NewPositions[1]);
        }
Ejemplo n.º 8
0
        public void Not_Position_When_Out_Of_Range_Of_Plateau()
        {
            // Arrange
            List <RoverRequest> roverInfoReq = new List <RoverRequest>
            {
                new RoverRequest {
                    Name = "Rover1", Instructions = "L"
                },
                new RoverRequest {
                    Name = "Rover2", Instructions = "MMMMM"
                },
                new RoverRequest {
                    Name = "Rover3", Instructions = "RRRRR"
                }
            };


            var sut = new RobotCreator();

            //Act
            var result = sut.CreateAndMoveRobots(roverInfoReq, new int[5, 5]);

            //Assert
            Assert.IsNotNull(result);

            //rover1
            Assert.IsTrue(result.First(z => z.Name == "Rover1").Message.ToLower().Contains("no plateau"));
            Assert.AreEqual(0, result.First(z => z.Name == "Rover1").NewPositions[0]);
            Assert.AreEqual(0, result.First(z => z.Name == "Rover1").NewPositions[1]);

            //rover2
            Assert.IsTrue(result.First(z => z.Name == "Rover2").Message.ToLower().Contains("no plateau"));
            Assert.AreEqual(0, result.First(z => z.Name == "Rover2").NewPositions[0]);
            Assert.AreEqual(0, result.First(z => z.Name == "Rover2").NewPositions[1]);

            //rover3
            Assert.IsTrue(result.First(z => z.Name == "Rover3").Message.ToLower().Contains("no plateau"));
            Assert.AreEqual(0, result.First(z => z.Name == "Rover3").NewPositions[0]);
            Assert.AreEqual(0, result.First(z => z.Name == "Rover3").NewPositions[1]);
        }
Ejemplo n.º 9
0
 private Robot CreateRobot(RobotModel model, RobotCreator creator)
 {
     return(creator.CreateRobot(model));
 }