Exemple #1
0
        Cube2 PrepareCube()
        {
            var cube = new Cube2();

            cube.Rotate("a1", 1);
            cube.Rotate("b1", 1);
            cube.Rotate("c1", 1);
            return(cube);
        }
Exemple #2
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);
        }
Exemple #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);
        }
Exemple #4
0
 public Cube2(Cube2 other)
 {
     for (int x = 0; x < COLORS_X; x++)
     {
         for (int y = 0; y < COLORS_Y; y++)
         {
             colors[y, x] = other.colors[y, x];
         }
     }
     for (int x = 0; x < PIECE_X; x++)
     {
         for (int y = 0; y < PIECE_Y; y++)
         {
             pieces[y, x] = other.pieces[y, x];
         }
     }
 }
Exemple #5
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 :(");
            }
        }
Exemple #6
0
 public bool EqualUsingMask(Cube2 other, int[,] mask)
 {
     return(ArrayEqualsUsingMask(colors, other.colors, mask));
 }
Exemple #7
0
 public bool EqualUsingMaskPiecesOnly(Cube2 other, int[,] mask)
 {
     return(ArrayEqualsUsingMask(pieces, other.pieces, mask));
 }
Exemple #8
0
 public bool EqualsPiecesOnly(Cube2 other)
 {
     return(ArrayEqualsUsingMask(pieces, other.pieces));
 }
Exemple #9
0
        public override bool Equals(object obj)
        {
            Cube2 other = (Cube2)obj;

            return(ArrayEqualsUsingMask(colors, other.colors));
        }