Exemplo n.º 1
0
        internal static List <PointI> DetermineMovementPath(HexLibrary hexLibrary, Stack stack, PointI from, PointI to, CellGrid cellGrid)
        {
            if (from.Equals(to))
            {
                return(new List <PointI>());
            }

            _hexLibrary = hexLibrary;
            AStarSearch <PointI, Cost> mapSolver = new MapSolver();

            mapSolver.GetAllNeighbors = GetAllNeighbors;
            mapSolver.GetDistance     = GetDistance;
            var openList   = new PriorityQueue <AStarSearch <PointI, Cost> .Node>();
            var closedList = new Dictionary <PointI, Cost>();

            mapSolver.Solve(GetCostToMoveIntoFunc, new PointI(cellGrid.NumberOfColumns, cellGrid.NumberOfRows), from, to, openList, closedList);

            var path = mapSolver.Solution;

            return(path);

            GetCostToMoveIntoResult GetCostToMoveIntoFunc(PointI point)
            {
                return(MovementCosts.GetCostToMoveInto(point, stack.MovementTypes, stack.MovementPoints));
            }
        }
        public void GetSpiralRing_EvenR()
        {
            var hexLibrary = new HexLibrary(HexType.PointyTopped, OffsetCoordinatesType.Even, 64.0f);

            var ring1 = hexLibrary.GetSpiralRing(new HexOffsetCoordinates(2, 2), 2);

            Assert.AreEqual(19, ring1.Length);
            Assert.AreEqual(new HexOffsetCoordinates(2, 2), ring1[0]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 3), ring1[1]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 2), ring1[2]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 1), ring1[3]);
            Assert.AreEqual(new HexOffsetCoordinates(3, 1), ring1[4]);
            Assert.AreEqual(new HexOffsetCoordinates(3, 2), ring1[5]);
            Assert.AreEqual(new HexOffsetCoordinates(3, 3), ring1[6]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 4), ring1[7]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 3), ring1[8]);
            Assert.AreEqual(new HexOffsetCoordinates(0, 2), ring1[9]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 1), ring1[10]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 0), ring1[11]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 0), ring1[12]);
            Assert.AreEqual(new HexOffsetCoordinates(3, 0), ring1[13]);
            Assert.AreEqual(new HexOffsetCoordinates(4, 1), ring1[14]);
            Assert.AreEqual(new HexOffsetCoordinates(4, 2), ring1[15]);
            Assert.AreEqual(new HexOffsetCoordinates(4, 3), ring1[16]);
            Assert.AreEqual(new HexOffsetCoordinates(3, 4), ring1[17]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 4), ring1[18]);
        }
        public void GetSingleRing_EvenR()
        {
            var hexLibrary = new HexLibrary(HexType.PointyTopped, OffsetCoordinatesType.Even, 64.0f);

            var ring1 = hexLibrary.GetSingleRing(new HexOffsetCoordinates(1, 1), 1);

            Assert.AreEqual(6, ring1.Length);
            Assert.AreEqual(new HexOffsetCoordinates(0, 2), ring1[0]);
            Assert.AreEqual(new HexOffsetCoordinates(0, 1), ring1[1]);
            Assert.AreEqual(new HexOffsetCoordinates(0, 0), ring1[2]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 0), ring1[3]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 1), ring1[4]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 2), ring1[5]);

            var ring2 = hexLibrary.GetSingleRing(new HexOffsetCoordinates(2, 2), 2);

            Assert.AreEqual(12, ring2.Length);
            Assert.AreEqual(new HexOffsetCoordinates(1, 4), ring2[0]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 3), ring2[1]);
            Assert.AreEqual(new HexOffsetCoordinates(0, 2), ring2[2]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 1), ring2[3]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 0), ring2[4]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 0), ring2[5]);
            Assert.AreEqual(new HexOffsetCoordinates(3, 0), ring2[6]);
            Assert.AreEqual(new HexOffsetCoordinates(4, 1), ring2[7]);
            Assert.AreEqual(new HexOffsetCoordinates(4, 2), ring2[8]);
            Assert.AreEqual(new HexOffsetCoordinates(4, 3), ring2[9]);
            Assert.AreEqual(new HexOffsetCoordinates(3, 4), ring2[10]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 4), ring2[11]);
        }
Exemplo n.º 4
0
        public void OffsetCoordinatesToCube_EvenQ()
        {
            var hexLibrary = new HexLibrary(HexType.FlatTopped, OffsetCoordinatesType.Even, 64.0f);

            var cube1  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-2, -2));
            var cube2  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-1, -2));
            var cube3  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(0, -2));
            var cube4  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(1, -2));
            var cube5  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(2, -2));
            var cube6  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-2, -1));
            var cube7  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-1, -1));
            var cube8  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(0, -1));
            var cube9  = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(1, -1));
            var cube10 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(2, -1));
            var cube11 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-2, 0));
            var cube12 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-1, 0));
            var cube13 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(0, 0));
            var cube14 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(1, 0));
            var cube15 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(2, 0));
            var cube16 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-2, 1));
            var cube17 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-1, 1));
            var cube18 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(0, 1));
            var cube19 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(1, 1));
            var cube20 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(2, 1));
            var cube21 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-2, 2));
            var cube22 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(-1, 2));
            var cube23 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(0, 2));
            var cube24 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(1, 2));
            var cube25 = hexLibrary.OffsetCoordinatesToCube(new HexOffsetCoordinates(2, 2));

            Assert.AreEqual(new HexCubeCoordinates(-2, 3, -1), cube1);
            Assert.AreEqual(new HexCubeCoordinates(-1, 3, -2), cube2);
            Assert.AreEqual(new HexCubeCoordinates(0, 2, -2), cube3);
            Assert.AreEqual(new HexCubeCoordinates(1, 2, -3), cube4);
            Assert.AreEqual(new HexCubeCoordinates(2, 1, -3), cube5);
            Assert.AreEqual(new HexCubeCoordinates(-2, 2, 0), cube6);
            Assert.AreEqual(new HexCubeCoordinates(-1, 2, -1), cube7);
            Assert.AreEqual(new HexCubeCoordinates(0, 1, -1), cube8);
            Assert.AreEqual(new HexCubeCoordinates(1, 1, -2), cube9);
            Assert.AreEqual(new HexCubeCoordinates(2, 0, -2), cube10);
            Assert.AreEqual(new HexCubeCoordinates(-2, 1, 1), cube11);
            Assert.AreEqual(new HexCubeCoordinates(-1, 1, 0), cube12);
            Assert.AreEqual(new HexCubeCoordinates(0, 0, 0), cube13);
            Assert.AreEqual(new HexCubeCoordinates(1, 0, -1), cube14);
            Assert.AreEqual(new HexCubeCoordinates(2, -1, -1), cube15);
            Assert.AreEqual(new HexCubeCoordinates(-2, 0, 2), cube16);
            Assert.AreEqual(new HexCubeCoordinates(-1, 0, 1), cube17);
            Assert.AreEqual(new HexCubeCoordinates(0, -1, 1), cube18);
            Assert.AreEqual(new HexCubeCoordinates(1, -1, 0), cube19);
            Assert.AreEqual(new HexCubeCoordinates(2, -2, 0), cube20);
            Assert.AreEqual(new HexCubeCoordinates(-2, -1, 3), cube21);
            Assert.AreEqual(new HexCubeCoordinates(-1, -1, 2), cube22);
            Assert.AreEqual(new HexCubeCoordinates(0, -2, 2), cube23);
            Assert.AreEqual(new HexCubeCoordinates(1, -2, 1), cube24);
            Assert.AreEqual(new HexCubeCoordinates(2, -3, 1), cube25);
        }
Exemplo n.º 5
0
        public void OffsetCoordinatesToAxial_EvenR()
        {
            var hexLibrary = new HexLibrary(HexType.PointyTopped, OffsetCoordinatesType.Even, 64.0f);

            var axial1  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-2, -2));
            var axial2  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-1, -2));
            var axial3  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(0, -2));
            var axial4  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(1, -2));
            var axial5  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(2, -2));
            var axial6  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-2, -1));
            var axial7  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-1, -1));
            var axial8  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(0, -1));
            var axial9  = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(1, -1));
            var axial10 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(2, -1));
            var axial11 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-2, 0));
            var axial12 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-1, 0));
            var axial13 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(0, 0));
            var axial14 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(1, 0));
            var axial15 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(2, 0));
            var axial16 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-2, 1));
            var axial17 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-1, 1));
            var axial18 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(0, 1));
            var axial19 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(1, 1));
            var axial20 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(2, 1));
            var axial21 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-2, 2));
            var axial22 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(-1, 2));
            var axial23 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(0, 2));
            var axial24 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(1, 2));
            var axial25 = hexLibrary.OffsetCoordinatesToAxial(new HexOffsetCoordinates(2, 2));

            Assert.AreEqual(new HexAxialCoordinates(-1, -2), axial1);
            Assert.AreEqual(new HexAxialCoordinates(0, -2), axial2);
            Assert.AreEqual(new HexAxialCoordinates(1, -2), axial3);
            Assert.AreEqual(new HexAxialCoordinates(2, -2), axial4);
            Assert.AreEqual(new HexAxialCoordinates(3, -2), axial5);
            Assert.AreEqual(new HexAxialCoordinates(-2, -1), axial6);
            Assert.AreEqual(new HexAxialCoordinates(-1, -1), axial7);
            Assert.AreEqual(new HexAxialCoordinates(0, -1), axial8);
            Assert.AreEqual(new HexAxialCoordinates(1, -1), axial9);
            Assert.AreEqual(new HexAxialCoordinates(2, -1), axial10);
            Assert.AreEqual(new HexAxialCoordinates(-2, 0), axial11);
            Assert.AreEqual(new HexAxialCoordinates(-1, 0), axial12);
            Assert.AreEqual(new HexAxialCoordinates(0, 0), axial13);
            Assert.AreEqual(new HexAxialCoordinates(1, 0), axial14);
            Assert.AreEqual(new HexAxialCoordinates(2, 0), axial15);
            Assert.AreEqual(new HexAxialCoordinates(-3, 1), axial16);
            Assert.AreEqual(new HexAxialCoordinates(-2, 1), axial17);
            Assert.AreEqual(new HexAxialCoordinates(-1, 1), axial18);
            Assert.AreEqual(new HexAxialCoordinates(0, 1), axial19);
            Assert.AreEqual(new HexAxialCoordinates(1, 1), axial20);
            Assert.AreEqual(new HexAxialCoordinates(-3, 2), axial21);
            Assert.AreEqual(new HexAxialCoordinates(-2, 2), axial22);
            Assert.AreEqual(new HexAxialCoordinates(-1, 2), axial23);
            Assert.AreEqual(new HexAxialCoordinates(0, 2), axial24);
            Assert.AreEqual(new HexAxialCoordinates(1, 2), axial25);
        }
Exemplo n.º 6
0
        public World(int numberOfColumns, int numberOfRows, Faction faction)
        {
            _turnNumber = 0;

            HexLibrary       = new HexLibrary(HexType.FlatTopped, OffsetCoordinatesType.Odd, 64.0f); // new HexLibrary(HexType.PointyTopped, OffsetCoordinatesType.Odd, 64.0f);
            OverlandMap      = new OverlandMap(numberOfColumns, numberOfRows);
            NotificationList = new NotificationList();

            PlayerFaction = faction;
            Settlements   = new Settlements();
            Stacks        = new Stacks();
        }
        public void GetAllNeighbors_OddQ()
        {
            var hexLibrary = new HexLibrary(HexType.FlatTopped, OffsetCoordinatesType.Odd, 64.0f);

            var neighbors = hexLibrary.GetAllNeighbors(new HexOffsetCoordinates(1, 1));

            Assert.AreEqual(6, neighbors.Length);
            Assert.AreEqual(new HexOffsetCoordinates(1, 0), neighbors[0]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 1), neighbors[1]);
            Assert.AreEqual(new HexOffsetCoordinates(2, 2), neighbors[2]);
            Assert.AreEqual(new HexOffsetCoordinates(1, 2), neighbors[3]);
            Assert.AreEqual(new HexOffsetCoordinates(0, 2), neighbors[4]);
            Assert.AreEqual(new HexOffsetCoordinates(0, 1), neighbors[5]);
        }
Exemplo n.º 8
0
        public void Test_FlatTopped()
        {
            IHex hexLibrary = new HexLibrary(HexType.FlatTopped, OffsetCoordinatesType.Odd, 64.0f);

            Assert.AreEqual(HexType.FlatTopped, hexLibrary.HexType);
            Assert.AreEqual(64.0f, hexLibrary.Size);
            Assert.AreEqual(128.0f, hexLibrary.Width);
            Assert.AreEqual(110.85125f, hexLibrary.Height);

            Assert.AreEqual(55.4256248f, hexLibrary.Apothem);
            Assert.AreEqual(110.85125f, hexLibrary.SideToSide);
            Assert.AreEqual(384.0f, hexLibrary.Perimeter);
            Assert.AreEqual(64.0f, hexLibrary.SideLength);
            Assert.AreEqual(64.0f, hexLibrary.CenterToVertex);
            Assert.AreEqual(128.0f, hexLibrary.VertexToVertex);
        }
        public void GetNeighbor_EvenQ()
        {
            var hexLibrary = new HexLibrary(HexType.FlatTopped, OffsetCoordinatesType.Even, 64.0f);

            var neighborN  = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.North);
            var neighborNE = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.NorthEast);
            var neighborSE = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.SouthEast);
            var neighborS  = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.South);
            var neighborSW = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.SouthWest);
            var neighborNW = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.NorthWest);

            Assert.AreEqual(new HexOffsetCoordinates(1, 0), neighborN);
            Assert.AreEqual(new HexOffsetCoordinates(2, 0), neighborNE);
            Assert.AreEqual(new HexOffsetCoordinates(2, 1), neighborSE);
            Assert.AreEqual(new HexOffsetCoordinates(1, 2), neighborS);
            Assert.AreEqual(new HexOffsetCoordinates(0, 1), neighborSW);
            Assert.AreEqual(new HexOffsetCoordinates(0, 0), neighborNW);
        }
Exemplo n.º 10
0
        public void GetNeighbor_OddR()
        {
            var hexLibrary = new HexLibrary(HexType.PointyTopped, OffsetCoordinatesType.Odd, 64.0f);

            var neighborNE = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.NorthEast);
            var neighborE  = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.East);
            var neighborSE = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.SouthEast);
            var neighborSW = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.SouthWest);
            var neighborW  = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.West);
            var neighborNW = hexLibrary.GetNeighbor(new HexOffsetCoordinates(1, 1), Direction.NorthWest);

            Assert.AreEqual(new HexOffsetCoordinates(2, 0), neighborNE);
            Assert.AreEqual(new HexOffsetCoordinates(2, 1), neighborE);
            Assert.AreEqual(new HexOffsetCoordinates(2, 2), neighborSE);
            Assert.AreEqual(new HexOffsetCoordinates(1, 2), neighborSW);
            Assert.AreEqual(new HexOffsetCoordinates(0, 1), neighborW);
            Assert.AreEqual(new HexOffsetCoordinates(1, 0), neighborNW);
        }