public void SetObstacle_OutOfMaterix()
    {
        AStarEightDirections aStar = new AStarEightDirections(10, 10);

        aStar.SetObstacle(new Vector2(-1, 3));
        aStar.SetObstacle(new Vector2(1, -3));
        aStar.SetObstacle(new Vector2(5, 10));
        aStar.SetObstacle(new Vector2(25, 3));

        foreach (AStarEightDirectionsHeapNode node in aStar.matrix)
        {
            Assert.IsTrue(node.canThrough);
        }
    }
    public void RemoveObstacle_OutOfMaterix()
    {
        Vector2 obstaclePosition = new Vector2(5, 3);

        AStarEightDirections aStar = new AStarEightDirections(10, 10);

        aStar.SetObstacle(obstaclePosition);

        aStar.RemoveObstacle(new Vector2(100, 5));
        aStar.RemoveObstacle(new Vector2(5, 100));
        aStar.RemoveObstacle(new Vector2(-10, 5));
        aStar.RemoveObstacle(new Vector2(5, -10));

        for (int x = 0; x < aStar.matrix.GetLength(0); x++)
        {
            for (int y = 0; y < aStar.matrix.GetLength(1); y++)
            {
                if (x != (int)obstaclePosition.x || y != (int)obstaclePosition.y)
                {
                    Assert.IsTrue(aStar.matrix[x, y].canThrough);
                }
                else
                {
                    Assert.IsFalse(aStar.matrix[x, y].canThrough);
                }
            }
        }
    }
    public void RemoveObstacle_Normal()
    {
        Vector2 obstaclePosition = new Vector2(5, 3);

        AStarEightDirections aStar = new AStarEightDirections(10, 10);

        aStar.SetObstacle(obstaclePosition);
        aStar.RemoveObstacle(obstaclePosition);

        foreach (AStarEightDirectionsHeapNode node in aStar.matrix)
        {
            Assert.IsTrue(node.canThrough);
        }
    }
    public void Pathfind_EndIsObstacle()
    {
        AStarEightDirections aStar = new AStarEightDirections(7, 7);

        Vector2 startPosition = new Vector2(0, 0);
        Vector2 endPosition   = new Vector2(6, 6);

        aStar.SetObstacle(new Vector2(6, 6));

        aStar.FindPath(startPosition, endPosition);

        foreach (AStarEightDirectionsHeapNode node in aStar.matrix)
        {
            Assert.AreEqual(null, node.nextNode);
        }
    }
Ejemplo n.º 5
0
    void MouseMiddleDown()
    {
        Vector2 position = GetMousePosition();

        AStarEightDirectionsHeapNode node = _aStar.GetNode(position);

        if (node == null)
        {
            return;
        }

        if (node.canThrough)
        {
            _aStar.SetObstacle(position);
        }
        else
        {
            _aStar.RemoveObstacle(position);
        }

        DoFindPath();
    }