Exemplo n.º 1
0
        public void RandomTest()
        {
            Random random      = new Random(7777777);
            int    repetitions = 20;

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

            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                Alg       scramble = Alg.FromRandomMoves(random.Next(20, 30), random);
                CubieCube cube     = CubieCube.FromAlg(scramble);

                Alg solution = TwoPhaseSolver.FindSolution(cube, timeout, returnLength, requiredLength);
                Console.WriteLine("\nScramble: " + 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);
            }
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public void CombineUAndDEdgeCoordsTest()
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            double[] phase2probabilities =
            {
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d,
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d
            };

            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                Alg       alg  = Alg.FromRandomMoves(length, random, phase2probabilities);
                CubieCube cube = CubieCube.FromAlg(alg);

                int uEdgeCoord = Coordinates.GetUEdgePermutation(cube);
                int dEdgeCoord = Coordinates.GetDEdgePermutation(cube);
                int result     = Coordinates.CombineUEdgePermutationAndDEdgeOrder(uEdgeCoord, dEdgeCoord % Coordinates.NumDEdgeOrders);
                int expected   = Coordinates.GetUdEdgeOrder(cube);

                Assert.AreEqual(expected, result);
            }
        }
Exemplo n.º 4
0
        public void EoCoordTest() //Tests GetEOCoord, SetEOCoord
        {
            Random random = new Random(7777777);
            int    length = 50;

            //if applying GetEOCoord and SetEOCoord results in the same array as at the beginning
            CubieCube expected = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
            CubieCube result   = CubieCube.CreateSolved();

            int coord = Coordinates.GetEdgeOrientation(expected);

            Coordinates.SetEdgeOrientation(result, coord);

            CollectionAssert.AreEqual(expected.EdgeOrientation, result.EdgeOrientation);

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

            CollectionAssert.AreEqual(expected.EdgeOrientation, result.EdgeOrientation);

            result = CubieCube.CreateSolved();

            Assert.AreEqual(0, Coordinates.GetEdgeOrientation(result));

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

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetEdgeOrientation(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEdgeOrientation(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEdgeOrientation(CubieCube.CreateSolved(), Coordinates.NumEdgeOrientations));
        }
Exemplo n.º 5
0
        public void OperatorTest()
        {
            Random random = new Random(7777777);
            int    length1 = 50, length2 = 50;
            int    times = 4;

            Alg nullAlg = null;

            // +
            Alg alg1    = Alg.FromRandomMoves(length1, random);
            Alg alg2    = Alg.FromRandomMoves(length2, random);
            Alg addTest = alg1 + alg2;

            Assert.AreEqual(alg1, Alg.FromEnumerable(addTest, 0,
                                                     alg1.Length));
            Assert.AreEqual(alg2, Alg.FromEnumerable(addTest, alg1.Length,
                                                     alg1.Length + alg2.Length));

            Assert.ThrowsException <ArgumentNullException>(() => nullAlg + alg1);
            Assert.ThrowsException <ArgumentNullException>(() => alg1 + nullAlg);

            // *
            Alg multiplyTest = alg1 * times;

            for (int i = 0; i < times; i++)
            {
                Assert.AreEqual(alg1, Alg.FromEnumerable(multiplyTest,
                                                         i * alg1.Length, (i + 1) * alg1.Length));
            }

            Assert.ThrowsException <ArgumentNullException>(() => nullAlg * times);
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => alg1 * -1);
        }
Exemplo n.º 6
0
        public void ReduceEoEquatorCoordinateTest()
        {
            Random random = new Random(7777777);
            int    length = 30;
            int    count  = 100;

            for (int i = 0; i < count; i++)
            {
                CubieCube cube = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
                for (int sym = 0; sym < NumSymmetriesDh4; sym++)
                {
                    CubieCube symCube = Symmetries.SymmetryCubes[sym].Clone();
                    symCube.Multiply(cube);
                    symCube.Multiply(Symmetries.SymmetryCubes[Symmetries.InverseIndex[sym]]);

                    int cubeEoEquator        = GetEoEquatorCoord(cube);
                    int cubeReducedEoEquator = SymmetryReduction.ReduceEoEquatorCoordinate[cubeEoEquator];

                    int symCubeEoEquator       = GetEoEquatorCoord(symCube);
                    int symCubeReducedEoEqutor = SymmetryReduction.ReduceEoEquatorCoordinate[symCubeEoEquator];

                    Assert.AreEqual(cubeReducedEoEquator, symCubeReducedEoEqutor);
                }
            }
        }
Exemplo n.º 7
0
        public void CpCoordTest() //Tests GetCpCoord, SetCpCoord
        {
            Random random = new Random(7777777);
            int    length = 50;

            //if applying GetCpCoord and SetCpCoord results in the same array as at the beginning
            CubieCube expected = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
            CubieCube result   = CubieCube.CreateSolved();

            int coord = Coordinates.GetCornerPermutation(expected);

            Coordinates.SetCornerPermutation(result, coord);

            CollectionAssert.AreEqual(expected.CornerPermutation, result.CornerPermutation);

            //apply R2 to a solved cube
            CubieCube cube = CubieCube.CreateSolved();

            cube.ApplyMove(Move.R2);

            int expectedCoord = 36177;
            int resultCoord   = Coordinates.GetCornerPermutation(cube);

            Assert.AreEqual(expectedCoord, resultCoord);

            expected = CubieCube.CreateSolved();
            expected.ApplyMove(Move.R2);

            result = CubieCube.CreateSolved();
            Coordinates.SetCornerPermutation(result, expectedCoord);

            CollectionAssert.AreEqual(expected.CornerPermutation, result.CornerPermutation);

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

            CollectionAssert.AreEqual(expected.CornerPermutation, result.CornerPermutation);

            result = CubieCube.CreateSolved();

            Assert.AreEqual(0, Coordinates.GetCornerPermutation(result));

            //example from http://kociemba.org/math/coordlevel
            Corner[] cp = new Corner[] { Corner.DFR, Corner.UFL, Corner.ULB, Corner.URF, Corner.DRB, Corner.DLF, Corner.DBL, Corner.UBR };
            cube          = CubieCube.Create(cp, CubieCube.SolvedCO, CubieCube.SolvedEP, CubieCube.SolvedEO, CubieCube.SolvedCenters);
            resultCoord   = Coordinates.GetCornerPermutation(cube);
            expectedCoord = 21021;
            Assert.AreEqual(expectedCoord, resultCoord);

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

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetCornerPermutation(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetCornerPermutation(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetCornerPermutation(CubieCube.CreateSolved(), Coordinates.NumCornerPermutations));
        }
Exemplo n.º 8
0
        public void FromRandomMoves2Test()
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 1000;

            double[] probabilities = Enumerable
                                     .Repeat(0d, Constants.NumMoves)
                                     .ToArray();

            probabilities[9] = 100000;
            probabilities[3] = 1;
            probabilities[4] = 1;
            probabilities[5] = 1;
            probabilities[6] = 3;

            Move[] possibleMoves = { Move.L1, Move.U1, Move.U2, Move.U3, Move.F1 };

            int[] sumOfMoves = Enumerable.
                               Repeat(0, Constants.NumMoves)
                               .ToArray();

            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                int lastCount = sumOfMoves.Sum();

                Alg randomAlg = Alg.FromRandomMoves(length, random, probabilities);
                Assert.AreEqual(length, randomAlg.Length);

                for (int move = 0; move < Constants.NumMoves; move++)
                {
                    sumOfMoves[move] += randomAlg.Count(randomMove => randomMove == (Move)move);
                }

                Assert.AreEqual(length, sumOfMoves.Sum() - lastCount);
            }
            Assert.AreEqual(length * repetitions, sumOfMoves.Sum());

            double[] effectiveProbabilities = sumOfMoves
                                              .Select(count => count / (double)(length * repetitions))
                                              .ToArray();

            //make sure only move with probability > 0 occur
            double impossibleMoveProbability = effectiveProbabilities
                                               .Where((probability, index) => !possibleMoves.Contains((Move)index))
                                               .Sum();

            Assert.AreEqual(0d, impossibleMoveProbability);

            //compare the effective probabilities
            double delta = 0.02d;

            Assert.AreEqual(1 / 2d, effectiveProbabilities[9], delta);
            Assert.AreEqual(1 / 4d, effectiveProbabilities[6], delta);
            Assert.AreEqual(1 / 12d, effectiveProbabilities[3], delta);
            Assert.AreEqual(1 / 12d, effectiveProbabilities[4], delta);
            Assert.AreEqual(1 / 12d, effectiveProbabilities[5], delta);
        }
Exemplo n.º 9
0
        public void GetHashCodeTest()
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            for (int rep = 0; rep < repetitions; rep++)
            {
                Alg alg   = Alg.FromRandomMoves(length, random);
                Alg clone = Alg.FromEnumerable(alg);
                Assert.AreEqual(alg.GetHashCode(), clone.GetHashCode());
            }
        }
Exemplo n.º 10
0
        public void EpCoordTest() //Tests GetCpCoord, SetCpCoord
        {
            Random random = new Random(7777777);
            int    length = 50;

            //if applying GetEpCoord and SetEpCoord results in the same array as at the beginning
            CubieCube expected = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
            CubieCube result   = CubieCube.CreateSolved();

            int coord = Coordinates.GetEdgePermutation(expected);

            Coordinates.SetEdgePermutation(result, coord);

            CollectionAssert.AreEqual(expected.EdgePermutation, result.EdgePermutation);

            //apply R2 to a solved cube
            CubieCube cube = CubieCube.CreateSolved();

            cube.ApplyMove(Move.R2);

            int expectedCoord = 123763104;
            int resultCoord   = Coordinates.GetEdgePermutation(cube);

            Assert.AreEqual(expectedCoord, resultCoord);

            expected = CubieCube.CreateSolved();
            expected.ApplyMove(Move.R2);

            result = CubieCube.CreateSolved();
            Coordinates.SetEdgePermutation(result, expectedCoord);

            CollectionAssert.AreEqual(expected.EdgePermutation, result.EdgePermutation);

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

            CollectionAssert.AreEqual(expected.EdgePermutation, result.EdgePermutation);

            result = CubieCube.CreateSolved();

            Assert.AreEqual(0, Coordinates.GetEdgePermutation(result));

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

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetEdgePermutation(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEdgePermutation(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEdgePermutation(CubieCube.CreateSolved(), Coordinates.NumEdgePermutations));
        }
Exemplo n.º 11
0
        public void EquatorDistributionCoordTest() //Tests GetEquatorDistributionCoord, SetEquatorDistributionCoord
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            CubieCube expected;
            CubieCube result;
            int       expectedCoord;
            int       resultCoord;

            Move[] phase2Moves = { Move.R2, Move.L2, Move.F2, Move.B2, Move.U1, Move.U2, Move.U3, Move.D1, Move.D2, Move.D3 };

            IEnumerable <Move> randomPhase2Moves()
            {
                yield return(phase2Moves[random.Next(0, phase2Moves.Length)]);
            }

            //solved tests
            Assert.AreEqual(0, Coordinates.GetEquatorDistribution(CubieCube.CreateSolved()));

            expected = CubieCube.CreateSolved();

            for (int i = 0; i < repetitions; i++)
            {
                result        = CubieCube.FromAlg(randomPhase2Moves().Take(length));
                expectedCoord = Coordinates.GetEquatorDistribution(expected);
                resultCoord   = Coordinates.GetEquatorDistribution(result);

                Assert.AreEqual(expectedCoord, resultCoord);
            }

            //scrambled tests
            for (int i = 0; i < repetitions; i++)
            {
                result        = CubieCube.CreateSolved();
                expected      = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
                expectedCoord = Coordinates.GetEquatorDistribution(expected);
                Coordinates.SetEquatorDistribution(result, expectedCoord);
                resultCoord = Coordinates.GetEquatorDistribution(result);
                Assert.AreEqual(expectedCoord, resultCoord);
            }

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

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetEquatorDistribution(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEquatorDistribution(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEquatorDistribution(CubieCube.CreateSolved(), Coordinates.NumEquatorDistributions));
        }
Exemplo n.º 12
0
        public void GetEnumeratorTest()
        {
            Random random = new Random(7777777);
            int    length = 50;

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

            int index = 0;

            foreach (Move move in alg)
            {
                Assert.AreEqual(alg[index++], move);
            }
            Assert.AreEqual(alg.Length, index);
        }
Exemplo n.º 13
0
        public void Inverse()
        {
            CubieCube expected    = CubieCube.CreateSolved();
            Random    random      = new Random(7777777);
            int       length      = 50;
            int       repetitions = 50;

            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                Alg       alg    = Alg.FromRandomMoves(length, random);
                CubieCube result = CubieCube.FromAlg(alg);
                result.Inverse();
                result.ApplyAlg(alg);

                Assert.AreEqual(expected, result);
            }
        }
Exemplo n.º 14
0
        public void TestAllPhase1()
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            TableController.InitializeCornerOrientationMoveTable();
            TableController.InitializeCornerPermutationMoveTable();
            TableController.InitializeEdgeOrientationMoveTable();
            TableController.InitializeEquatorDistributionMoveTable();

            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                Alg randomMoves = Alg.FromRandomMoves(length, random);

                int resultCo = 0;
                int resultCp = 0;
                int resultEo = 0;
                int resultEquatorDistribution = 0;

                CubieCube cube = CubieCube.CreateSolved();

                for (int moveIndex = 0; moveIndex < length; moveIndex++)
                {
                    resultCo = TableController.CornerOrientationMoveTable[resultCo, (int)randomMoves[moveIndex]];
                    resultCp = TableController.CornerPermutationMoveTable[resultCp, (int)randomMoves[moveIndex]];
                    resultEo = TableController.EdgeOrientationMoveTable[resultEo, (int)randomMoves[moveIndex]];
                    resultEquatorDistribution = TableController.EquatorDistributionMoveTable[resultEquatorDistribution, (int)randomMoves[moveIndex]];

                    cube.ApplyMove(randomMoves[moveIndex]);
                }

                int expectedCo = Coordinates.GetCornerOrientation(cube);
                Assert.AreEqual(expectedCo, resultCo);

                int expectedCp = Coordinates.GetCornerPermutation(cube);
                Assert.AreEqual(expectedCp, resultCp);

                int expectedEo = Coordinates.GetEdgeOrientation(cube);
                Assert.AreEqual(expectedEo, resultEo);

                int expectedEquatorDistribution = Coordinates.GetEquatorDistribution(cube);
                Assert.AreEqual(expectedEquatorDistribution, resultEquatorDistribution);
            }
        }
Exemplo n.º 15
0
        public void UEdgeCoordTest()
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            CubieCube expected;
            CubieCube result;
            int       expectedCoord;
            int       resultCoord;

            double[] phase2probabilities =
            {
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d,
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d
            };

            //solved tests
            Assert.AreEqual(0, Coordinates.GetUEdgeDistribution(CubieCube.CreateSolved()));

            //scrambled tests
            for (int i = 0; i < repetitions; i++)
            {
                result        = CubieCube.CreateSolved();
                expected      = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
                expectedCoord = Coordinates.GetUEdgePermutation(expected);
                Coordinates.SetUEdgePermutation(result, expectedCoord);
                resultCoord = Coordinates.GetUEdgePermutation(result);

                int expectedDistribution = expectedCoord / Coordinates.NumUEdgePermutations;
                int expectedPermutation  = expectedCoord % Coordinates.NumUEdgePermutations;
                int resultDistribution   = resultCoord / Coordinates.NumUEdgePermutations;
                int resultPermutation    = resultCoord % Coordinates.NumUEdgePermutations;

                Assert.AreEqual(expectedDistribution, resultDistribution);
                Assert.AreEqual(expectedPermutation, resultPermutation);
            }

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

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetUEdgePermutation(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetUEdgePermutation(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetUEdgePermutation(CubieCube.CreateSolved(), Coordinates.NumUEdgePermutations));
        }
Exemplo n.º 16
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));
        }
Exemplo n.º 17
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));
        }
Exemplo n.º 18
0
        public void UdEdgeOrderCoordTest() //Tests GetUdEdgePermutationCoord, SetUdEdgePermutationCoord
        {
            Random random = new Random(7777777);
            int    length = 50;

            double[] phase2probabilities =
            {
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d,
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d
            };

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

            Coordinates.SetUdEdgeOrder(result, 0);

            CollectionAssert.AreEqual(expected.EdgePermutation.Take(8).ToArray(), result.EdgePermutation.Take(8).ToArray());

            result = CubieCube.CreateSolved();

            Assert.AreEqual(0, Coordinates.GetUdEdgeOrder(result));

            //if applying GetUdEdgePermutationCoord and
            //SetUdEdgePermutationCoord results in the same array as at the
            //beginning
            Alg randomAlg = Alg.FromRandomMoves(length, random, phase2probabilities);

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

            int coord = Coordinates.GetUdEdgeOrder(expected);

            Coordinates.SetUdEdgeOrder(result, coord);

            CollectionAssert.AreEqual(expected.EdgePermutation.Take(8).ToArray(), result.EdgePermutation.Take(8).ToArray());

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

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetUdEdgeOrder(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetUdEdgeOrder(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetUdEdgeOrder(CubieCube.CreateSolved(), Coordinates.NumUdEdgeOrders));
        }
Exemplo n.º 19
0
        public void TestAllPhase2()
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            TableController.InitializeUdEdgeOrderMoveTable();
            TableController.InitializeEquatorOrderMoveTable();

            double[] moveProbabilities =
            {
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d,
                0d, 1d, 0d, 1d, 1d, 1d, 0d, 1d, 0d
            };

            int expectedEquatorPermutation;

            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                Alg randomMoves = Alg.FromRandomMoves(length, random, moveProbabilities);

                int resultUdEdgeOrder        = 0;
                int resultEquatorPermutation = 0;

                CubieCube cube = CubieCube.CreateSolved();

                for (int moveIndex = 0; moveIndex < length; moveIndex++)
                {
                    resultUdEdgeOrder        = TableController.UdEdgeOrderMoveTable[resultUdEdgeOrder, MoveTables.Phase1IndexToPhase2Index[(int)randomMoves[moveIndex]]];
                    resultEquatorPermutation = TableController.EquatorOrderMoveTable[resultEquatorPermutation, (int)randomMoves[moveIndex]];

                    cube.ApplyMove(randomMoves[moveIndex]);

                    expectedEquatorPermutation = Coordinates.GetEquatorOrder(cube);
                    Assert.AreEqual(expectedEquatorPermutation, resultEquatorPermutation);
                }

                int expectedUdEdgeOrder = Coordinates.GetUdEdgeOrder(cube);
                Assert.AreEqual(expectedUdEdgeOrder, resultUdEdgeOrder);

                expectedEquatorPermutation = Coordinates.GetEquatorOrder(cube);
                Assert.AreEqual(expectedEquatorPermutation, resultEquatorPermutation);
            }
        }
Exemplo n.º 20
0
 private void enterTimeBox_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         if (enterTimeBox.Text == "")
         {
         }
         else if (enterTimeBox.Text == "next")
         {
             scrambleLabel.Text = Alg.FromRandomMoves(random.Next(15, 25), random).ToString();
             enterTimeBox.Text  = "";
         }
         else if (enterTimeBox.Text.All(char.IsDigit))
         {
             collectedData.Add(new CsTimerData()
             {
                 Number       = collectedData.Count + 1,
                 Date         = DateTime.Now,
                 Scramble     = scrambleLabel.Text,
                 Milliseconds = int.Parse(enterTimeBox.Text)
             });
             scrambleLabel.Text = Alg.FromRandomMoves(random.Next(15, 25), random).ToString();
             enterTimeBox.Text  = "";
         }
         else if (File.Exists(enterTimeBox.Text))
         {
             if (path != null)
             {
                 CsTimerData.WriteCsTimerData(path, collectedData);
             }
             path = enterTimeBox.Text;
             collectedData.Clear();
             CsTimerData.ReadCsTimerData(path, it => collectedData.Add(it));
             enterTimeBox.Text  = "";
             scrambleLabel.Text = Alg.FromRandomMoves(random.Next(15, 25), random).ToString();
         }
         else
         {
             enterTimeBox.Text = "Invalid: " + enterTimeBox.Text;
         }
     }
 }
Exemplo n.º 21
0
        public void MultiplyTest()
        {
            Random random = new Random(7777777);
            int    length = 50;

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

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

            foreach (Move move in alg)
            {
                expected.ApplyMove(move);
                CubieCube moveCube = CubieCube.CreateSolved();
                moveCube.ApplyMove(move);
                result.Multiply(moveCube);
            }

            Assert.AreEqual(expected, result);
            Assert.ThrowsException <ArgumentNullException>(()
                                                           => CubieCube.CreateSolved().Multiply(null));
        }
Exemplo n.º 22
0
        public void FromRandomMovesTest()
        {
            Random random = new Random(7777777);
            int    length = 50;

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

            Assert.AreEqual(Alg.Empty, Alg.FromRandomMoves(0, random));

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

            Assert.AreEqual(length, randomAlg.Length);

            var enumerator = randomAlg.GetEnumerator();

            if (enumerator.MoveNext())
            {
                Move previous2 = enumerator.Current;
                if (enumerator.MoveNext())
                {
                    Move previous1 = enumerator.Current;
                    Assert.AreNotEqual(previous1.Face(), previous2.Face());
                    while (enumerator.MoveNext())
                    {
                        Assert.AreNotEqual(enumerator.Current.Face(), previous1.Face());
                        if (enumerator.Current.Axis() == previous1.Axis())
                        {
                            Assert.AreNotEqual(enumerator.Current.Axis(), previous2.Axis());
                        }
                        previous2 = previous1;
                        previous1 = enumerator.Current;
                    }
                }
            }
        }
Exemplo n.º 23
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));
        }