コード例 #1
0
        private void StartSearch()
        {
            #region rotate cube
            CubieCube rotatedCube = CubieCube.CreateSolved();

            for (int i = 0; i < _rotation; i++)
            {
                rotatedCube.Rotate(Rotation.y3);
                rotatedCube.Rotate(Rotation.x3);
            }

            rotatedCube.Multiply(_notRotatedCube);

            for (int i = 0; i < _rotation; i++)
            {
                rotatedCube.Rotate(Rotation.x1);
                rotatedCube.Rotate(Rotation.y1);
            }

            if (_inversed)
            {
                rotatedCube.Inverse();
            }
            #endregion rotate cube

            //calculate coordinates
            int co      = Coordinates.GetCornerOrientation(rotatedCube);
            int cp      = Coordinates.GetCornerPermutation(rotatedCube);
            int eo      = Coordinates.GetEdgeOrientation(rotatedCube);
            int equator = Coordinates.GetEquatorPermutation(rotatedCube);
            int uEdges  = Coordinates.GetUEdgePermutation(rotatedCube);
            int dEdges  = Coordinates.GetDEdgePermutation(rotatedCube);

            //store coordinates used in phase 2
            _cp     = cp;
            _uEdges = uEdges;
            _dEdges = dEdges;

            int pruningIndex    = PruningTables.GetPhase1PruningIndex(co, eo, equator / Coordinates.NumEquatorOrders);
            int minPhase1Length = TableController.Phase1PruningTable[pruningIndex];
            int maxPhase1Length = (_requiredLength > 0 && _requiredLength < GodsNumber) ? _requiredLength : GodsNumber;

            _currentPhase1Solution = new int[maxPhase1Length];
            _currentPhase2Solution = new int[MaxPhase2Length];

            for (int phase1Length = minPhase1Length; phase1Length < maxPhase1Length; phase1Length++)
            {
                SearchPhase1(eo, co, equator, depth: 0, remainingMoves: phase1Length, minPhase1Length);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        private void StartSearch()
        {
            #region rotate cube
            CubieCube rotatedCube = CubieCube.CreateSolved();

            for (int i = 0; i < _rotation; i++)
            {
                rotatedCube.Rotate(Rotation.y3);
                rotatedCube.Rotate(Rotation.x3);
            }

            rotatedCube.Multiply(_notRotatedCube);

            for (int i = 0; i < _rotation; i++)
            {
                rotatedCube.Rotate(Rotation.x1);
                rotatedCube.Rotate(Rotation.y1);
            }

            if (_inversed)
            {
                rotatedCube.Inverse();
            }
            #endregion rotate cube

            #region rotate weights
            _rotatedWeights = new float[NumMoves];

            for (int oldIndex = 0; oldIndex < NumMoves; oldIndex++)
            {
                int newIndex = oldIndex;
                for (int i = 0; i < _rotation; i++)
                {
                    newIndex = (int)((Move)newIndex).Rotate(Rotation.x1).Rotate(Rotation.y1);
                }
                _rotatedWeights[newIndex] = _nonRotatedWeights[oldIndex];
            }

            if (_inversed)
            {
                for (int face = 0; face < NumFaces; face++)
                {
                    //face * 3 = 90° cw, face * 3 + 2 = 90° ccw
                    float temp = _rotatedWeights[face * 3];
                    _rotatedWeights[face * 3]     = _rotatedWeights[face * 3 + 2];
                    _rotatedWeights[face * 3 + 2] = temp;
                }
            }
            #endregion rotate weights

            _phase1MoveOrder = MoveWeightsUtils.OrderedMoves((Move[])Enum.GetValues(typeof(Move)), _rotatedWeights);
            _phase2MoveOrder = MoveWeightsUtils.OrderedMoves(TwoPhaseConstants.Phase2Moves, _rotatedWeights);

            //calculate coordinates
            int co      = Coordinates.GetCornerOrientation(rotatedCube);
            int cp      = Coordinates.GetCornerPermutation(rotatedCube);
            int eo      = Coordinates.GetEdgeOrientation(rotatedCube);
            int equator = Coordinates.GetEquatorPermutation(rotatedCube);
            int uEdges  = Coordinates.GetUEdgePermutation(rotatedCube);
            int dEdges  = Coordinates.GetDEdgePermutation(rotatedCube);

            //store coordinates used in phase 2
            _cp     = cp;
            _uEdges = uEdges;
            _dEdges = dEdges;

            int pruningIndex    = PruningTables.GetPhase1PruningIndex(co, eo, equator / Coordinates.NumEquatorOrders);
            int minPhase1Length = TableController.Phase1PruningTable[pruningIndex];

            _currentPhase1Solution = new int[MaxPhase1Length];
            _currentPhase2Solution = new int[MaxPhase2Length];

            for (int phase1Length = minPhase1Length; phase1Length < MaxPhase1Length; phase1Length++)
            {
                SearchPhase1(eo, co, equator, depth: 0, remainingMoves: phase1Length, minPhase1Length);
            }
        }