Exemplo n.º 1
0
        private string m_S; // solution string

        #endregion Fields

        #region Constructors

        protected Solver()
        {
            _top = new CubeSide(YELLOW, 'T', TopMove);
            _front = new CubeSide(BLUE, 'F', FrontMove);
            _right = new CubeSide(RED, 'R', RightMove);
            _left = new CubeSide(ORANGE, 'L', LeftMove);
            _back = new CubeSide(GREEN, 'B', BackMove);
            _down = new CubeSide(WHITE, 'D', DownMove);

            _oTop = new CubeSide(YELLOW, 'T', TopMove);
            _oFront = new CubeSide(BLUE, 'F', FrontMove);
            _oRight = new CubeSide(RED, 'R', RightMove);
            _oLeft = new CubeSide(ORANGE, 'L', LeftMove);
            _oBack = new CubeSide(GREEN, 'B', BackMove);
            _oDown = new CubeSide(WHITE, 'D', DownMove);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Rotate cube clock wise
        /// </summary>
        /// <param name="side">Side to rotate</param>
        protected virtual void RotateCW(CubeSide side)
        {
            if (side != null)
            {
                RotateFaceCW(side);

                Square[] moves = side.Moves;
                char tmp1 = GetSide(moves[9].Side).Block[moves[9].Row, moves[9].Col];
                char tmp2 = GetSide(moves[10].Side).Block[moves[10].Row, moves[10].Col];
                char tmp3 = GetSide(moves[11].Side).Block[moves[11].Row, moves[11].Col];

                for (int i = 8; i >= 0; i--)
                {
                    GetSide(moves[i + 3].Side).Block[moves[i + 3].Row, moves[i + 3].Col] =
                        GetSide(moves[i].Side).Block[moves[i].Row, moves[i].Col];
                }

                GetSide(moves[0].Side).Block[moves[0].Row, moves[0].Col] = tmp1;
                GetSide(moves[1].Side).Block[moves[1].Row, moves[1].Col] = tmp2;
                GetSide(moves[2].Side).Block[moves[2].Row, moves[2].Col] = tmp3;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Save the face of cube
 /// </summary>
 /// <param name="pSide">Side need to save</param>
 /// <param name="pSaveTo">Side saved to</param>
 private void SaveSide(CubeSide pSide, CubeSide pSaveTo)
 {
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             pSaveTo.Block[i, j] = pSide.Block[i, j];
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Rotate a face clock wise
        /// </summary>
        /// <param name="side">side of face</param>
        private void RotateFaceCW(CubeSide side)
        {
            char tmp1 = side.Block[1, 2];
            char tmp2 = side.Block[2, 2];

            side.Block[2, 2] = side.Block[0, 2];
            side.Block[1, 2] = side.Block[0, 1];
            side.Block[0, 2] = side.Block[0, 0];

            side.Block[0, 2] = side.Block[0, 0];
            side.Block[0, 1] = side.Block[1, 0];
            side.Block[0, 0] = side.Block[2, 0];

            side.Block[1, 0] = side.Block[2, 1];
            side.Block[2, 0] = tmp2;
            side.Block[2, 1] = tmp1;
        }
Exemplo n.º 5
0
        private int GetCornersSide(CubeSide side1, CubeSide side2)
        {
            int flag = 0;
            // back vs right <=> front vs left
            // front vs right <=> back vs left
            // right vs front <=> left vs back
            // left vs front <=> right vs back
            if (side1 == _back)
            {
                if (side2 == _right)
                {
                    flag |= SRIGHT;
                }
                else
                {
                    flag |= SBACK;
                }
            }

            if (side1 == _front)
            {
                if (side2 == _right)
                {
                    flag |= SFRONT;
                }
                else
                {
                    flag |= SLEFT;
                }
            }

            if (side1 == _right)
            {
                if (side2 == _front)
                {
                    flag |= SFRONT;
                }
                else
                {
                    flag |= SRIGHT;
                }
            }

            if (side1 == _left)
            {
                if (side2 == _front)
                {
                    flag |= SLEFT;
                }
                else
                {
                    flag |= SBACK;
                }
            }
            return flag;
        }
Exemplo n.º 6
0
        private void Rotate3DCW(CubeSide side)
        {
            if (side != null)
            {
                int numTurns = _speed/50;

                if (numTurns < 2)
                {
                    numTurns = 2;
                }

                while (90 % numTurns != 0)
                {
                    numTurns++;
                }

                int degrees = 90/numTurns;

                switch (side.Side)
                {
                    case 'F':
                        for (int i = 0; i < numTurns; i++)
                        {
                            _cube3D.RotateZ(2, -degrees);
                            UpdateCube();
                        }
                        break;
                    case 'B':
                        for (int i = 0; i < numTurns; i++)
                        {
                            _cube3D.RotateZ(0, degrees);
                            UpdateCube();
                        }
                        break;
                    case 'R':
                        for (int i = 0; i < numTurns; i++)
                        {
                            _cube3D.RotateX(2, -degrees);
                            UpdateCube();
                        }
                        break;
                    case 'L':
                        for (int i = 0; i < numTurns; i++)
                        {
                            _cube3D.RotateX(0, degrees);
                            UpdateCube();
                        }
                        break;
                    case 'T':
                        for (int i = 0; i < numTurns; i++)
                        {
                            _cube3D.RotateY(2, -degrees);
                            UpdateCube();
                        }
                        break;
                    case 'D':
                        for (int i = 0; i < numTurns; i++)
                        {
                            _cube3D.RotateY(0, degrees);
                            UpdateCube();
                        }
                        break;
                }
            }
        }
Exemplo n.º 7
0
 protected override void RotateCW(CubeSide side)
 {
     base.RotateCW(side);
     Rotate3DCW(side);
 }