Exemple #1
0
        private static Piece MakePiece(PieceDescription pieceDescription)
        {
            var northPattern          = pieceDescription.Pattern;
            var westPattern           = StringManipulations.RotateStrings(northPattern);
            var southPattern          = StringManipulations.RotateStrings(westPattern);
            var eastPattern           = StringManipulations.RotateStrings(southPattern);
            var northReflectedPattern = StringManipulations.ReflectStrings(northPattern);
            var westReflectedPattern  = StringManipulations.ReflectStrings(westPattern);
            var southReflectedPattern = StringManipulations.ReflectStrings(southPattern);
            var eastReflectedPattern  = StringManipulations.ReflectStrings(eastPattern);
            var allPatternVariations  = new[] {
                new PatternVariation(Orientation.North, false, northPattern),
                new PatternVariation(Orientation.West, false, westPattern),
                new PatternVariation(Orientation.South, false, southPattern),
                new PatternVariation(Orientation.East, false, eastPattern),
                new PatternVariation(Orientation.North, true, northReflectedPattern),
                new PatternVariation(Orientation.West, true, westReflectedPattern),
                new PatternVariation(Orientation.South, true, southReflectedPattern),
                new PatternVariation(Orientation.East, true, eastReflectedPattern)
            };
            var uniquePatternVariations = allPatternVariations.Distinct(new PatternVariationComparer());
            var uniqueVariations        = uniquePatternVariations
                                          .Select(upv =>
                                                  new Variation(upv.Orientation, upv.Reflected, PatternToCoords(upv.Pattern)))
                                          .ToImmutableArray();

            return(new Piece(pieceDescription.Label, uniqueVariations));
        }
Exemple #2
0
        public static bool SolutionIsUnique(
            ImmutableArray <Placement> placements,
            ImmutableList <string> uniqueBoards)
        {
            var board1 = Pentominoes.FormatSolution(placements);
            var board2 = StringManipulations.RotateStrings(board1);
            var board3 = StringManipulations.RotateStrings(board2);
            var board4 = StringManipulations.RotateStrings(board3);
            var board5 = StringManipulations.ReflectStrings(board1);
            var board6 = StringManipulations.ReflectStrings(board2);
            var board7 = StringManipulations.ReflectStrings(board3);
            var board8 = StringManipulations.ReflectStrings(board4);
            var boards = new[] {
                string.Join("|", board1),
                string.Join("|", board2),
                string.Join("|", board3),
                string.Join("|", board4),
                string.Join("|", board5),
                string.Join("|", board6),
                string.Join("|", board7),
                string.Join("|", board8)
            };

            return(uniqueBoards.Intersect(boards).Count() == 0);
        }