示例#1
0
        public void PopulatePattern(List <Slot> pattern, int patternCount)
        {
            Combinations       Combo       = new Combinations();
            List <PuzzlePiece> twoPieces   = Pieces.GetRange(0, 2);
            List <PuzzlePiece> threePieces = Pieces.GetRange(2, 7);

            List <List <PuzzlePiece> > resultsThree = Combo.GeneratePermutations <PuzzlePiece>(threePieces);
            List <List <PuzzlePiece> > resultsTwo   = Combo.GeneratePermutations <PuzzlePiece>(twoPieces);

            Console.WriteLine($"Testing pattern #{patternCount}");

            foreach (List <PuzzlePiece> twoPiece in resultsTwo)
            {
                List <List <PuzzlePiece> > twoMirrorPieces = generateMirrorPermuations(twoPiece);

                foreach (List <PuzzlePiece> mirrorPerm in twoMirrorPieces)
                {
                    for (int i = 0; i < mirrorPerm.Count; i++)
                    {
                        PlacePiece(pattern[i], mirrorPerm[i]);
                    }
                    foreach (List <PuzzlePiece> threePiece in resultsThree)
                    {
                        List <List <PuzzlePiece> > threeMirrorPieces = generateMirrorPermuations(threePiece);
                        foreach (List <PuzzlePiece> mirrorPermThree in threeMirrorPieces)
                        {
                            for (int j = 0; j < mirrorPermThree.Count; j++)
                            {
                                PlacePiece(pattern[j + 2], mirrorPermThree[j]);
                            }

                            if (CheckGridValidity())
                            {
                                Console.WriteLine("-----------------------------------------------------------");
                                Console.WriteLine("Valid Solution for Pattern #" + patternCount);
                                PrintMatrix(Grid);
                                PrintNumberPattern(pattern);
                            }
                        }
                    }
                }
            }
        }