Beispiel #1
0
        public void EquatorPermutationCoordTest() //Tests GetEquatorPermutationCoord, SetEquatorPermutationCoord
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            //if solved permutation corresponds to the coordinate 0
            //SetEquatorPermutationCoord()
            CubieCube expected = CubieCube.CreateSolved();
            CubieCube result   = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));

            Coordinates.SetEquatorOrder(result, 0);
            CubingAssert.HaveEqualEquatorEdgePermutation(expected, result);

            expected = CubieCube.FromAlg(Alg.FromString("R2 L2"));
            result   = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
            Coordinates.SetEquatorOrder(result, Coordinates.NumEquatorOrders - 1);

            //GetEquatorPermutationCoord()
            result = CubieCube.CreateSolved();
            Assert.AreEqual(0, Coordinates.GetEquatorOrder(result));

            result.ApplyAlg(Alg.FromString("F' R' B' D' L2"));
            Assert.AreEqual(0, Coordinates.GetEquatorOrder(result));

            //apply B1
            int       expectedCoord = 17;
            CubieCube cube          = CubieCube.CreateSolved();

            cube.ApplyMove(Move.B1);
            int resultCoord = Coordinates.GetEquatorOrder(cube);

            Assert.AreEqual(expectedCoord, resultCoord);

            //apply B2
            expectedCoord = 6;
            cube          = CubieCube.CreateSolved();
            cube.ApplyMove(Move.B2);
            resultCoord = Coordinates.GetEquatorOrder(cube);
            Assert.AreEqual(expectedCoord, resultCoord);

            //if applying GetEquatorPermutationCoord() and SetEquatorPermutationCoord() results in the same array as at the beginning
            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                expected = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
                result   = CubieCube.CreateSolved();

                int coord = Coordinates.GetEquatorOrder(expected);
                Coordinates.SetEquatorOrder(result, coord);

                CubingAssert.HaveEqualEquatorEdgePermutation(expected, result);
            }

            //exceptions
            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.GetEquatorOrder(null));

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetEquatorOrder(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEquatorOrder(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEquatorOrder(CubieCube.CreateSolved(), Coordinates.NumEquatorOrders));
        }
Beispiel #2
0
        public void FromStringTest()
        {
            string alg = "B R' F2 D'";

            Assert.AreEqual(alg, Alg.ToString(Alg.FromString(alg)));
            Assert.ThrowsException <ArgumentException>(() => Alg.FromString("Exp"));
            Assert.ThrowsException <ArgumentNullException>(() => Alg.FromString(null));
        }
Beispiel #3
0
        public void IndexerTest()
        {
            Alg alg = Alg.FromString("R U2 F'");

            Assert.AreEqual(Move.R1, alg[0]);
            Assert.AreEqual(Move.U2, alg[1]);
            Assert.AreEqual(Move.F3, alg[2]);
            Assert.ThrowsException <IndexOutOfRangeException>(() => alg[-1]);
            Assert.ThrowsException <IndexOutOfRangeException>(() => alg[4]);
        }
Beispiel #4
0
        public void GetNumberOfEachMoveTest()
        {
            Alg alg = Alg.FromString("L2 B F' R L2 F2 L2 R");

            int[] expected =
            {
                2, 0, 0, 0, 0, 0, 0, 1, 1,
                0, 3, 0, 0, 0, 0, 1, 0, 0
            };
            int[] result = alg.GetCountOfEachMove();

            CollectionAssert.AreEqual(expected, result);
        }
Beispiel #5
0
        public void SexyMoveTest(Action <CubieCube, CubieCube> test)
        {
            Alg sexyMove = Alg.FromString("R U R' U'");

            foreach (Rotation rotation in Enum.GetValues(typeof(Rotation)))
            {
                CubieCube expected = CubieCube.CreateSolved();
                CubieCube result   = CubieCube.CreateSolved();
                result.ApplyAlg(sexyMove.Rotate(rotation) * 6);

                test(expected, result);
            }
        }
Beispiel #6
0
        public void StaticTest(string algString)
        {
            Alg       scramble = Alg.FromString(algString);
            CubieCube cube     = CubieCube.FromAlg(scramble);

            TimeSpan timeout       = TimeSpan.FromSeconds(1);
            float    returnValue   = 4000;
            float    requiredValue = 5000;

            float[] weights =
            {
                169.658122242946f,
                253.796705882179f,
                211.084512473536f,
                206.193406852305f,
                299.809258427086f,
                155.496912851115f,
                158.690899467791f,
                281.70422762001f,
                346.448146439892f,
                274.885031555195f,
                311.019164835258f,
                258.486161100002f,
                196.885474673572f,
                275.657440421246f,
                214.624405800259f,
                322.649818802591f,
                354.012863621357f,
                321.02200029978f
            };

            float[] weightedPhase2PruningTable = WeightedPruningTables.CreateWeightedPhase2CornerEquatorTable(weights);

            Alg solution = WeightedTwoPhaseSolver.FindSolution(cube, timeout, returnValue, requiredValue, weights, weightedPhase2PruningTable);

            Console.WriteLine("Scramble: " + scramble + "\nSolution: " + solution + "\nLength: " + solution.Length);

            Assert.IsTrue(solution.Select(move => weights[(int)move]).Sum() <= requiredValue);

            CubieCube expected = CubieCube.CreateSolved();
            CubieCube result   = CubieCube.CreateSolved();

            result.ApplyAlg(scramble);
            result.ApplyAlg(solution);

            Assert.AreEqual(expected, result);
        }
Beispiel #7
0
        public void CornerUdTable2DataTest(string algString)
        {
            TableController.InitializePhase2CornerUdPruningTable();

            Alg       alg  = Alg.FromString(algString);
            CubieCube cube = CubieCube.FromAlg(alg);

            int udEdgeOrder       = Coordinates.GetUdEdgeOrder(cube);
            int cornerPermutation = Coordinates.GetCornerPermutation(cube);

            int pruningIndex = PruningTables.GetPhase2CornerUdPruningIndex(udEdgeOrder, cornerPermutation);

            int pruningValue = TableController.Phase2CornerUdPruningTable[pruningIndex];

            Assert.IsTrue(pruningValue <= alg.Length);
            Console.WriteLine(pruningValue);
        }
Beispiel #8
0
        public void CornerEquatorTable2DataTest(string algString)
        {
            TableController.InitializePhase2CornerEquatorPruningTable();

            Alg       alg  = Alg.FromString(algString);
            CubieCube cube = CubieCube.FromAlg(alg);

            int cornerPermutation  = Coordinates.GetCornerPermutation(cube);
            int equatorPermutation = Coordinates.GetEquatorOrder(cube);

            int pruningIndex = Coordinates.NumEquatorOrders * cornerPermutation + equatorPermutation;

            int pruningValue = TableController.Phase2CornerEquatorPruningTable[pruningIndex];

            Assert.IsTrue(pruningValue <= alg.Length);
            Console.WriteLine(pruningValue);
        }
Beispiel #9
0
        public void RotateTest()
        {
            Random random = new Random(7777777);
            int    length = 50;

            Rotation rotation = Rotation.x1;

            Alg original = Alg.FromString("B2 D U'");
            Alg expected = Alg.FromString("D2 F B'");

            Assert.AreEqual(expected, original.Rotate(rotation));

            Alg randomMoves = Alg.FromRandomMoves(length, random);

            Assert.AreEqual(randomMoves.Inverse(), Alg.Inverse(randomMoves));
            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           Alg.Rotate(null, rotation));
        }
Beispiel #10
0
        public void InverseTest()
        {
            Random random = new Random(7777777);
            int    length = 50;

            Alg original = Alg.FromString("R U R' F' R U R' U' R' F R2 U' R' U'");
            Alg expected = Alg.FromString("U R U R2 F' R U R U' R' F R U' R'");
            Alg result   = Alg.Inverse(original);

            Assert.AreEqual(expected, result);

            Alg randomMoves = Alg.FromRandomMoves(length, random);

            Assert.AreEqual(randomMoves, Alg.Inverse(Alg.Inverse(randomMoves)));
            Assert.AreEqual(randomMoves, randomMoves.Inverse().Inverse());
            Assert.AreEqual(randomMoves.Inverse(), Alg.Inverse(randomMoves));
            Assert.ThrowsException <ArgumentNullException>(() => Alg.Inverse(null));
        }
Beispiel #11
0
        public void Table1DataTest(string algString)
        {
            TableController.InitializePhase1PruningTable();

            Alg       alg  = Alg.FromString(algString);
            CubieCube cube = CubieCube.FromAlg(alg);

            int co      = Coordinates.GetCornerOrientation(cube);
            int eo      = Coordinates.GetEdgeOrientation(cube);
            int equator = Coordinates.GetEquatorDistribution(cube);

            int pruningIndex = PruningTables.GetPhase1PruningIndex(co, eo, equator);

            int pruningValue = TableController.Phase1PruningTable[pruningIndex];

            Assert.IsTrue(pruningValue <= alg.Length);
            Console.WriteLine(pruningValue);
        }
Beispiel #12
0
        public void CostTooHighTest() //There used to be an error when solving this scramble
        {
            string    algString = "B2 D B F' D L U B U' F' R' F2 B' L' F' R B2 R' U R' L2 D R2 F2 L B2";
            Alg       scramble  = Alg.FromString(algString);
            CubieCube cube      = CubieCube.FromAlg(scramble);

            TimeSpan timeout       = TimeSpan.FromSeconds(0);
            float    requiredValue = 4700f;

            float[] weights =
            {
                169.658122242946f, // R
                253.796705882179f, // R2
                211.084512473536f, // R'
                206.193406852305f, // U
                299.809258427086f, // U2
                155.496912851115f, // U'
                158.690899467791f, // F
                281.70422762001f,  // F2
                346.448146439892f, // F'
                274.885031555195f, // L
                311.019164835258f, // L2
                258.486161100002f, // L'
                196.885474673572f, // D
                275.657440421246f, // D2
                214.624405800259f, // D'
                322.649818802591f, // B
                354.012863621357f, // B2
                321.02200029978f   // B'
            };

            float[] weightedPhase2PruningTable = WeightedPruningTables.CreateWeightedPhase2CornerEquatorTable(weights);

            Alg solution = WeightedTwoPhaseSolver.FindSolution(cube, timeout, requiredValue, requiredValue, weights, weightedPhase2PruningTable);

            float cost = solution.Select(move => weights[(int)move])
                         .Sum();

            Assert.IsTrue(cost <= requiredValue);

            Console.WriteLine("\nScramble: " + scramble + "\nSolution: " + solution + "\nCost: " + cost + " Length: " + solution.Length);
        }
Beispiel #13
0
        public void MoveReplacementTest(Action <CubieCube, CubieCube> test)
        {
            Alg uReplacementAlg = Alg.FromString("R L' F2 B2 R L' D L R' B2 F2 L R'");

            foreach (Move move in Enum.GetValues(typeof(Move)))
            {
                foreach (Rotation rotation in Enum.GetValues(typeof(Rotation)))
                {
                    if (Face.U.Rotate(rotation) == move.Face())
                    {
                        CubieCube result = CubieCube.CreateSolved();
                        result.ApplyMove(move);
                        CubieCube expected = CubieCube.CreateSolved();
                        expected.ApplyAlg(uReplacementAlg.Rotate(rotation) * move.QuarterTurns());

                        test(expected, result);
                    }
                }
            }
        }
        public void StaticTest(string algString)
        {
            Alg       scramble = Alg.FromString(algString);
            CubieCube cube     = CubieCube.FromAlg(scramble);

            TimeSpan timeout        = TimeSpan.FromSeconds(1);
            int      returnLength   = 0;
            int      requiredLength = 20;

            Alg solution = TwoPhaseSolver.FindSolution(cube, timeout, returnLength, requiredLength);

            Console.WriteLine("Scramble: " + scramble + "\nSolution: " + solution + "\nLength: " + solution.Length);

            Assert.IsTrue(solution.Length <= 20);

            CubieCube expected = CubieCube.CreateSolved();
            CubieCube result   = CubieCube.CreateSolved();

            result.ApplyAlg(scramble);
            result.ApplyAlg(solution);

            Assert.AreEqual(expected, result);
        }
Beispiel #15
0
 public void LengthTest()
 {
     Assert.AreEqual(3, Alg.FromString("F2 D R'").Length);
     Assert.AreEqual(5, Alg.FromString("L B2 L2 B' F2").Length);
 }
Beispiel #16
0
        public void FromRandomMoves2ExceptionTest()
        {
            Random random = new Random(7777777);
            int    length = 50;

            double[] probabilities = Enumerable
                                     .Repeat(1d, 18)
                                     .ToArray();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Alg.FromRandomMoves(-1, random, probabilities));
            Assert.ThrowsException <ArgumentNullException>(() => Alg.FromRandomMoves(length, null, probabilities));
            Assert.ThrowsException <ArgumentNullException>(() => Alg.FromRandomMoves(length, random, null));

            //negative probability value
            probabilities[7] = -1;
            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(length, random, probabilities));

            //all probability values zero
            probabilities = Enumerable
                            .Repeat(0d, 18)
                            .ToArray();

            Alg lengthZero = Alg.FromRandomMoves(0, random, probabilities);

            Assert.AreEqual(0, lengthZero.Length);

            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(1, random, probabilities));

            //one probability value non-zero
            probabilities[7] = 1d;

            Alg lengthOne = Alg.FromRandomMoves(1, random, probabilities);

            Assert.AreEqual(Alg.FromString("F2"), lengthOne);

            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(2, random, probabilities));

            //two probability values non-zero
            probabilities[8] = 1d;
            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(2, random, probabilities));

            probabilities[8]  = 0d;
            probabilities[15] = 1d;

            Alg lengthTwo = Alg.FromRandomMoves(2, random, probabilities);

            CollectionAssert.AreEquivalent(Alg.FromString("F2 B").ToArray(), lengthTwo.ToArray());

            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(3, random, probabilities));

            //three probability values non-zero
            probabilities[8] = 1d;
            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(3, random, probabilities));

            probabilities[8] = 0d;
            probabilities[0] = 1d;

            Alg lengthThree = Alg.FromRandomMoves(3, random, probabilities);

            Assert.IsTrue(lengthThree.Contains(Move.R1));
        }