Esempio n. 1
0
        public void ProcessSensor_Should_Add_GivenSensorFiveByFiveSensorData_To_ExploredMap()
        {
            ExploredMap exploredMap = new ExploredMap(new Vector2Int(30, 30), new Vector2Int(2, 2));

            int[,] sensorData =
            {
                { -1, -1, -1, -1, -1 },
                { -1,  1,  0,  1, -1 },
                { -1,  0,  2,  1, -1 },
                { -1,  0,  0,  1, -1 },
                { -1,  1,  0,  1,  1 }
            };
            exploredMap.ProcessSensor(sensorData);
            int[,] expectedData =
            {
                { -1, -1, -1, -1, -1 },
                { -1,  1,  0,  1, -1 },
                { -1,  0,  2,  1, -1 },
                { -1,  0,  0,  1, -1 },
                { -1,  1,  0,  1,  1 }
            };
            var mazeArray = exploredMap.GetMazeArray();
            var saveData  = new int[5, 5];

            for (var i = 0; i < 5; i++)
            {
                for (var j = 0; j < 5; j++)
                {
                    saveData[i, j] = mazeArray[i, j];
                }
            }
            Assert.That(expectedData, Is.EqualTo(saveData));
        }
Esempio n. 2
0
        public void GetSensorRobotPosition_Should_Return_Position_For_ProximitySensor()
        {
            var exploredMap = new ExploredMap(new Vector2Int(30, 30), new Vector2Int(1, 1));
            var array       = new int[3, 3] {
                { -1, 1, -1 }, { 1, 2, 1 }, { -1, 0, -1 }
            };                                                               //Data like proximity sensor
            var result = exploredMap.GetSensorRobotPosition(array);

            Assert.That(result, Is.EqualTo(new Vector2Int(1, 1)));
        }
Esempio n. 3
0
        public void GetSensorRobotPosition_Should_Return_OneOne_For_FiveByFiveSensor()
        {
            ExploredMap exploredMap = new ExploredMap(new Vector2Int(30, 30), new Vector2Int(1, 1));

            int[,] sensorData = { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 2, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
            Vector2Int result   = exploredMap.GetSensorRobotPosition(sensorData);
            Vector2Int expected = new Vector2Int(2, 2);

            Assert.That(result, Is.EqualTo(expected));
        }
Esempio n. 4
0
        public void ProcessSensor_Should_Add_GivenSensorThreeByThreeSensorData_To_ExploredMap()
        {
            ExploredMap exploredMap = new ExploredMap(new Vector2Int(30, 30), new Vector2Int(1, 1));

            int[,] sensorData = { { -1, 1, 0 }, { 0, 2, 1 }, { -1, -1, 1 } };
            exploredMap.ProcessSensor(sensorData);
            var mazeArray = exploredMap.GetMazeArray();
            var saveData  = new int[3, 3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    saveData[i, j] = mazeArray[i, j];
                }
            }
            Assert.That(sensorData, Is.EqualTo(saveData));
        }
    //update explored maze on UI
    void updateExplored()
    {
        if (mazeWidth == 50)
        {
            mazeOffset = 190;
        }
        exploredMaze = exploration.GetExploredMap();
        for (int i = 0; i < exploredMazeObjects.Length; i++)
        {
            Destroy(exploredMazeObjects[i]);
        }
        counter = 0;


        for (int i = 0; i < mazeHeight; i++)
        {
            for (int j = 0; j < mazeWidth; j++)
            {
                Vector3  tempVector = new Vector3(xStart + (xSpace * j) + mazeOffset, 0, yStart - (ySpace * i));
                MazeCell mazeCell   = exploredMaze.GetCell(new Vector2Int(i, j));
                if (mazeCell == null)
                {
                    continue;
                }
                if (mazeCell.IsWallCell() == true)
                {
                    exploredMazeObjects[counter++] = Instantiate(wallPrefab, tempVector, Quaternion.identity);
                }
                else if (mazeCell.IsVisited() == false)
                {
                    exploredMazeObjects[counter++] = Instantiate(floorPrefab, tempVector, Quaternion.identity);
                }
                else if (exploredMaze.GetCell(new Vector2Int(i, j)).IsVisited())
                {
                    exploredMazeObjects[counter++] = Instantiate(visitedFloorPrefab, tempVector, Quaternion.identity);
                }
            }
        }
        Vector2Int vector        = exploredMaze.GetCurrentPosition();
        Vector3    robotPosition = new Vector3(xStart + (xSpace * vector.y) + mazeOffset, 0, yStart - (ySpace * vector.x));

        exploredMazeObjects[counter] = Instantiate(robotPrefab, robotPosition, Quaternion.identity);
        exploringRobot = exploredMazeObjects[counter++];
    }
 void moveInDirection(string direction)
 {
     batteryLife--;
     exploredMaze = exploration.GetExploredMap();
     if (direction == "North")
     {
         if (maze[currentX - 1, currentY + 0] == 1)
         {
             return;
         }
         exploredMaze.MoveRelative(Vector2Int.left);
         move(-1, 0);
         robot.transform.Rotate(0.0f, 270f, 0.0f, Space.Self);
     }
     else if (direction == "East")
     {
         if (maze[currentX, currentY + 1] == 1)
         {
             return;
         }
         exploredMaze.MoveRelative(Vector2Int.up);
         move(0, 1);
         robot.transform.Rotate(0.0f, 0f, 0.0f, Space.Self);
     }
     else if (direction == "West")
     {
         if (maze[currentX, currentY - 1] == 1)
         {
             return;
         }
         exploredMaze.MoveRelative(Vector2Int.down);
         move(0, -1);
         robot.transform.Rotate(0.0f, -180.0f, 0.0f, Space.Self);
     }
     else if (direction == "South")
     {
         if (maze[currentX + 1, currentY + 0] == 1)
         {
             return;
         }
         exploredMaze.MoveRelative(Vector2Int.right);
         move(1, 0);
         robot.transform.Rotate(0.0f, 90.0f, 0.0f, Space.Self);
     }
     else if (direction == "RNorth")
     {
         robotDirection = "North";
         robot.transform.Rotate(0.0f, 270f, 0.0f, Space.Self);
     }
     else if (direction == "RSouth")
     {
         robotDirection = "South";
         robot.transform.Rotate(0.0f, 90.0f, 0.0f, Space.Self);
     }
     else if (direction == "REast")
     {
         robotDirection = "East";
         robot.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
     }
     else if (direction == "RWest")
     {
         robotDirection = "West";
         robot.transform.Rotate(0.0f, -180.0f, 0.0f, Space.Self);
     }
 }
Esempio n. 7
0
 public void Initialize()
 {
     _map = new ExploredMap(new Vector2Int(3, 3), new Vector2Int(1, 1));
 }