Пример #1
0
        public void Test_4_VeryHard()
        {
            int index = 1;

            int[]   clues1    = { 0, 0, 0, 5, 0, 0, 3, 0, 6, 3, 4, 0, 0, 0, 3, 0, 0, 0, 2, 4, 0, 2, 6, 2, 2, 2, 0, 0 };
            int[][] expected1 =
            {
                new[] { 3, 5, 6, 1, 7, 2, 4 },
                new[] { 7, 6, 5, 2, 4, 3, 1 },
                new[] { 2, 7, 1, 3, 6, 4, 5 },
                new[] { 4, 3, 7, 6, 1, 5, 2 },
                new[] { 6, 4, 2, 5, 3, 1, 7 },
                new[] { 1, 2, 3, 4, 5, 7, 6 },
                new[] { 5, 1, 4, 7, 2, 6, 3 }
            };
            Stack <int> orderedClues = new Stack <int>(Enumerable.Range(0, 4 * Skyscrapers.Size)
                                                       .Select(clueIndex => new Tuple <int, int[]>(clueIndex, SkyscrapersTests4by4.GetLaneIndices2(clueIndex))).OrderBy(t => t.Item2[0])
                                                       .ThenBy(t => t.Item2[1]).Select(t => clues1[t.Item1]).Reverse());

            Skyscrapers.Expected = expected1;
            var actual = Skyscrapers.SolvePuzzle(clues1);

            CollectionAssert.AreEqual(expected1, actual,
                                      SkyscrapersTests4by4.ErrorMessage(expected1, actual, orderedClues));
        }
Пример #2
0
        public void Test_2_VeryHard()
        {
            int index = 1;

            int[]       clues1       = clues[index];
            int[][]     expected1    = expected[index];
            Stack <int> orderedClues = new Stack <int>(Enumerable.Range(0, 4 * Skyscrapers.Size)
                                                       .Select(clueIndex => new Tuple <int, int[]>(clueIndex, SkyscrapersTests4by4.GetLaneIndices2(clueIndex))).OrderBy(t => t.Item2[0])
                                                       .ThenBy(t => t.Item2[1]).Select(t => clues1[t.Item1]).Reverse());

            var actual = Skyscrapers.SolvePuzzle(clues1);

            CollectionAssert.AreEqual(expected1, actual,
                                      SkyscrapersTests4by4.ErrorMessage(expected1, actual, orderedClues));
        }
Пример #3
0
        public void SolvePuzzle4()
        {
            var clues = new[] { 4, 4, 0, 3, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 6, 3, 0, 0, 4, 0, 0, 0, 0 };

            var expected = new[] {
                new [] { 3, 1, 6, 2, 4, 5 },
                new [] { 4, 2, 5, 3, 1, 6 },
                new [] { 2, 5, 4, 6, 3, 1 },
                new [] { 5, 6, 3, 1, 2, 4 },
                new [] { 1, 4, 2, 5, 6, 3 },
                new [] { 6, 3, 1, 4, 5, 2 }
            };

            Stack <int> orderedClues = new Stack <int>(Enumerable.Range(0, 4 * Skyscrapers.Size)
                                                       .Select(clueIndex => new Tuple <int, int[]>(clueIndex, SkyscrapersTests4by4.GetLaneIndices2(clueIndex))).OrderBy(t => t.Item2[0])
                                                       .ThenBy(t => t.Item2[1]).Select(t => clues[t.Item1]).Reverse());

            var actual = Skyscrapers.SolvePuzzle(clues);

            CollectionAssert.AreEqual(expected, actual,
                                      SkyscrapersTests4by4.ErrorMessage(expected, actual, orderedClues));
        }
Пример #4
0
        public static string PrintValues(Backup backup = null)
        {
            Lane[]   allLanes = AllLanes;
            Cell[][] allCells = AllCells;
            if (backup != null)
            {
                allLanes = backup._allLanes;
                allCells = backup._allCells;
            }

            Stack <Lane> orderedClues = new Stack <Lane>(Enumerable.Range(0, 4 * Size)
                                                         .Select(clueIndex => new Tuple <int, int[]>(clueIndex, SkyscrapersTests4by4.GetLaneIndices2(clueIndex)))
                                                         .OrderBy(t => t.Item2[0])
                                                         .ThenBy(t => t.Item2[1]).Select(t => allLanes[t.Item1]).Reverse());

            string values = Environment.NewLine
                            + "      " +
                            string.Join(string.Concat(Enumerable.Range(0, 2 * Size - 2).Select(i => " ")),
                                        Enumerable.Range(0, Size).Select(i => orderedClues.Pop())) +
                            Environment.NewLine
                            + string.Join(Environment.NewLine,
                                          allCells.Select(r =>
                                                          orderedClues.Pop() + " |" +
                                                          string.Join("|", r.Select(c => string.Join(",", c.PossibleValues) + string.Concat(Enumerable.Range(0, Size - c.PossibleValues.Count).Select(i => "  ")))) + "| " +
                                                          orderedClues.Pop())) + Environment.NewLine
                            + "      " +
                            string.Join(string.Concat(Enumerable.Range(0, 2 * Size - 2).Select(i => " ")),
                                        Enumerable.Range(0, Size).Select(i => orderedClues.Pop())) +
                            Environment.NewLine;

            Debug.Print(values);
            Console.Write(values);
            return(values);
        }