示例#1
0
        List <List <string> > RecursivelyRotateAndCompare(
            Cube2 cube,
            char previousCh,
            int depth,
            Cube2 refCube,
            List <string> moves,
            int[,] colorMask,
            int[,] piecesMask,
            int maxDepth,
            Func <Cube2, Cube2, int[, ], int[, ], bool> eqFunc)
        {
            List <List <string> > result = null;

            if (depth != 1 && eqFunc(cube, refCube, colorMask, piecesMask))
            {
                result = new List <List <string> >();
                result.Add(moves);
                return(result);
            }

            if (depth > maxDepth)
            {
                return(result);
            }

            for (var ch = 'a'; ch <= 'c'; ch++)
            {
                if (ch == previousCh)
                {
                    continue;
                }

                for (int count = 1; count <= 3; count++)
                {
                    string move = ch + "1";
                    cube.Rotate(move, count);
                    List <string> newMoves = new List <string>(moves);
                    newMoves.Add(move + "/" + count);

                    var resultToAdd = RecursivelyRotateAndCompare(cube, ch, depth + 1, refCube, newMoves, colorMask, piecesMask, maxDepth, eqFunc);
                    if (resultToAdd != null)
                    {
                        if (result == null)
                        {
                            result = resultToAdd;
                        }
                        else
                        {
                            result.AddRange(resultToAdd);
                        }
                    }
                    cube.Rotate(move, -count);
                }
            }

            return(result);
        }
示例#2
0
        Cube2 PrepareCube()
        {
            var cube = new Cube2();

            cube.Rotate("a1", 1);
            cube.Rotate("b1", 1);
            cube.Rotate("c1", 1);
            return(cube);
        }
示例#3
0
        Cube2 PrepareCubeAndPrint()
        {
            var cube = new Cube2();

            cube.Rotate("a1", 1);
            cube.Rotate("b1", 1);
            cube.Rotate("c1", 1);
            Console.WriteLine(cube.ToStringWithPieces());
            return(cube);
        }
示例#4
0
        void PrintSolution(List <List <string> > result, Cube2 cube)
        {
            if (result != null && result.Count > 0)
            {
                result.Sort((x, y) => x.Count.CompareTo(y.Count));
                Console.WriteLine($"Paths found: {result.Count}");
                Console.WriteLine();
                for (int i = 0; i < result[0].Count; i++)
                {
                    Console.Write((i > 0 ? ", " : "") + (i + 1) + ". " + result[0][i]);
                }
                Console.WriteLine();
                Console.WriteLine();
                cube.Rotate(result[0]);

                Console.WriteLine(cube.ToStringWithPieces());
            }
            else
            {
                Console.WriteLine("No moves found :(");
            }
        }