Esempio n. 1
0
        public static Matrix <bool> ResizeMatrixTo7(Matrix <bool> matrix)
        {
            if (matrix is null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            var resizedMatrix = matrix.CreateMatrixWithMargins(1, 1);

            for (var x = 0; x < matrix.Width; x++)
            {
                for (var y = 0; y < matrix.Height; y++)
                {
                    if (matrix[x, y])
                    {
                        var neighbors = HexHelper.GetNeighbors(x + 1, y + 1);
                        foreach (var neightbor in neighbors)
                        {
                            var resizedX = neightbor.X;
                            var resizedY = neightbor.Y;
                            resizedMatrix[resizedX, resizedY] = true;
                        }
                    }
                }
            }

            return(resizedMatrix);
        }
Esempio n. 2
0
        public static bool IsAvailableFor7(Matrix <bool> matrix, OffsetCoords coords)
        {
            if (matrix is null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            if (!IsAvailableFor(matrix, coords))
            {
                return(false);
            }

            var neighbors = HexHelper.GetNeighbors(coords.X, coords.Y);

            foreach (var neightbor in neighbors)
            {
                if (!matrix.IsIn(neightbor.X, neightbor.Y))
                {
                    return(false);
                }

                if (!matrix[neightbor.X, neightbor.Y])
                {
                    return(false);
                }
            }

            return(true);
        }
        private static void PlaceArea(int x, int y, Matrix <bool> matrix)
        {
            matrix.Items[x, y] = true;
            var neighbors = HexHelper.GetNeighbors(x, y);

            foreach (var neightbor in neighbors)
            {
                matrix.Items[neightbor.X, neightbor.Y] = true;
            }
        }
        private static void DrawLineBetweenNodes(Matrix <bool> matrix, CubeCoords openCubeCoord, CubeCoords unitedCubeCoord)
        {
            var line = CubeCoordsHelper.CubeDrawLine(openCubeCoord, unitedCubeCoord);

            foreach (var lineItem in line)
            {
                var offsetCoords = HexHelper.ConvertToOffset(lineItem);
                matrix[offsetCoords.X, offsetCoords.Y] = true;

                // Коридоры должны быть размером в Size7.
                // Поэтому вокруг каждой точки прорываем соседей.

                var neighborCoords = HexHelper.GetNeighbors(offsetCoords.X, offsetCoords.Y);
                foreach (var coords in neighborCoords)
                {
                    matrix[coords.X, coords.Y] = true;
                }
            }
        }
Esempio n. 5
0
        public void ResizeMatrixTo7Test()
        {
            // ARRANGE

            var matrix = new Matrix <bool>(1, 1);

            matrix[0, 0] = true;

            // ACT

            var resizedMatrix = MapFactoryHelper.ResizeMatrixTo7(matrix);

            // ASSERT

            resizedMatrix[1, 1].Should().BeTrue();
            var n = HexHelper.GetNeighbors(1, 1);

            foreach (var c in n)
            {
                resizedMatrix[c.X, c.Y].Should().BeTrue();
            }
        }