Ejemplo n.º 1
0
        public void AStarCostMap()
        {
            var go = new GameObject();
            // TODO make a mock grid class to test with
            // hex grid instantiates our WARGrid abstact logic
            var   grid        = go.AddComponent <WARHexGrid>();
            float globalScale = 0.01f;

            float outterRadius = 1f * globalScale;
            float innerRadius  = outterRadius * Mathf.Sqrt(3) / 2f;

            float numberOfColumns = 3f;
            float numberOfRows    = 9f;

            // create a plane on the origin with an extent of 0.25f
            var plane = new UIPlane {
                center = Vector3.zero,
                extent = new Vector3(3f * numberOfColumns * outterRadius, 0f, numberOfRows * innerRadius)
            };
            var hex = new GameObject("hex cell");

            hex.AddComponent <WARActorCell>();
            hex.AddComponent <MeshRenderer>();
            var child = new GameObject();

            child.transform.SetParent(hex.transform);
            child.AddComponent <TextMesh>();

            // an astar pathfinder to test
            var finder = new WARPathAStar();


            // initialize our grid with this plane and an empty hex cell 'prefab'
            grid.initialize(plane, hex, finder);
            // create the grid to populate cell metadata
            grid.createGrid();

            // the source of the source map
            int cellId = 3;

            // compute the map relative to our source
            var map = finder.getCostMap(cellId, grid);

            // make sure the source has no cost
            Assert.AreEqual(0, map[cellId]);
            // check a few known values at each weight
            Assert.AreEqual(1, map[2]);
            Assert.AreEqual(2, map[10]);
            Assert.AreEqual(3, map[11]);
            Assert.AreEqual(3, map[9]);
            Assert.AreEqual(4, map[19]);
            Assert.AreEqual(5, map[20]);
        }
Ejemplo n.º 2
0
        public void AStarStraightPath()
        {
            var go = new GameObject();
            // TODO make a mock grid class to test with
            // hex grid instantiates our WARGrid abstact logic
            var   grid        = go.AddComponent <WARHexGrid>();
            float globalScale = 0.01f;

            float outterRadius = 1f * globalScale;
            float innerRadius  = outterRadius * Mathf.Sqrt(3) / 2f;

            float numberOfColumns = 3f;
            float numberOfRows    = 9f;

            // create a plane on the origin with an extent of 0.25f
            var plane = new UIPlane {
                center = Vector3.zero,
                extent = new Vector3(3f * numberOfColumns * outterRadius, 0f, numberOfRows * innerRadius)
            };
            var hex = new GameObject("hex cell");

            hex.AddComponent <WARActorCell>();
            hex.AddComponent <MeshRenderer>();
            var child = new GameObject();

            child.transform.SetParent(hex.transform);
            child.AddComponent <TextMesh>();

            // an astar pathfinder to test
            var finder = new WARPathAStar();


            // initialize our grid with this plane and an empty hex cell 'prefab'
            grid.initialize(plane, hex, finder);
            // create the grid to populate cell metadata
            grid.createGrid();

            // compute the path from 3 to 9
            var path = finder.findPath(3, 9, grid);
            // the path we expect back
            var target = new List <int> {
                3, 2, 10, 9
            };

            // make sure we got what we want
            Assert.AreEqual(target, path);
        }