コード例 #1
0
        public void Solver_TestGetIndexes_CompleteGridCoverage(int shapeId, int shapeSize)
        {
            // Arrange
            var factory = new GeniusSquareSolutionFactory();

            int[] cells = new int[36];

            // Act
            // Try to test shape in all permutations to ensure it can cover each grid cell
            for (int o = 0; o < Max; o += 45)         // 8 (potential) orientations
            {
                for (int x = 0; x < Max; x += 60)     // 6 (potential) columns
                {
                    for (int y = 0; y < Max; y += 60) // 6 (potential) rows
                    {
                        var indexes = factory.GetIndexes(shapeId, shapeValue: o, xValue: x, yValue: y);

                        foreach (int i in indexes)
                        {
                            cells[i]++;
                        }
                    }
                }
            }

            // Assert
            int emptyCells = cells.Count(x => x == 0);

            emptyCells.Should().Be(0);

            cells.Sum().Should().Be(8 * 6 * 6 * shapeSize);
        }
コード例 #2
0
        public GeniusSquareFitness(int[] blockers)
        {
            SolutionFactory = new GeniusSquareSolutionFactory();

            // Array representing 6 x 6 grid with blockers that we can add shapes to
            EmptySolutionWithBlockers =
                0.To(GridCells - 1)
                .Select(x => blockers.Contains(x) ? 1 : 0);
        }
コード例 #3
0
        public void Solver_TestGetIndexes_ShapesPositionedCorrectly
            (int shapeId, int shapeValue, int xValue, int yValue, int[] expected)
        {
            // Arrange
            var factory = new GeniusSquareSolutionFactory();

            // Act
            var indexes = factory.GetIndexes(shapeId, shapeValue, xValue, yValue);

            // Assert
            indexes.Should().BeEquivalentTo(expected);
        }