Beispiel #1
0
 public void Random()
 {
     if (!Unfolded)
     {
         _steps    = 0;
         _sequence = string.Empty;
         string[] ops = CubeOperation.GetRandomOps(10);
         foreach (string op in ops)
         {
             Rotate(op);
         }
     }
 }
Beispiel #2
0
        public string DoCommand(string commandString)
        {
            string text = commandString.Trim().ToUpper();

            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }
            string action = CubeOperation.GetOp(ref text, false, false);

            Op(action, 30);
            return(text);
        }
Beispiel #3
0
 public void EndTrack()
 {
     try
     {
         if (_rubikscube.NoOp && _prevHit != null)
         {
             if (_angle != null)
             {
                 double angle = (double)_angle;
                 if (System.Math.Abs(angle) > Angle.DegreesToRadians(10) && System.Math.Abs(angle) < Angle.DegreesToRadians(90))
                 {
                     if (_selected.SelectMode == SelectMode.Cubies)
                     {
                         //finish OP
                         RotationDirection dir = (angle > 0) ? RotationDirection.CounterClockWise : RotationDirection.Clockwise;
                         string            op  = CubeOperation.GetOp(_basicOp, dir);
                         if (!string.IsNullOrEmpty(op))
                         {
                             _rubikscube.Rotate(op, 20, false, angle, true);
                             //Debug.WriteLine(string.Format("op:{0}, angle:{1}", op, angle));
                         }
                     }
                     else
                     {
                     }
                 }
                 else
                 {
                     //Debug.WriteLine(string.Format("endtrack: {0}", angle));
                     //cancel OP
                     if (_selected.SelectMode == SelectMode.Cubies)
                     {
                         foreach (Cubie cubie in _selected.SelectedCubies)
                         {
                             cubie.Restore();
                         }
                     }
                     else
                     {
                         _rubikscube.Restore();
                     }
                 }
             }
             _prevHit = null;
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("EndTrack Error: " + e.ToString());
     }
 }
Beispiel #4
0
        public CubeSelection Select(Cubicle cubicle, Axis axis, out string basicOp)
        {
            CubeSelection cs = new CubeSelection();

            basicOp = string.Empty;
            //if (cubicle.Name.Length > 1)
            {//not center piece, select cubies
                cs.SelectMode     = SelectMode.Cubies;
                basicOp           = CubeOperation.GetBasicOp(cubicle.Name, axis).Op;
                cs.SelectedCubies = CubeOperation.BasicOps[basicOp].CubicleGroup.Select(c => _cubicles[c].Cubie);
            }

            /*
             * else //center piece
             * {
             *  cs.SelectMode = SelectMode.Cube;
             * }
             */
            return(cs);
        }
Beispiel #5
0
        private void AfterOp(string op)
        {
            bool isSolved = IsSolved();

            string text   = _sequence;// tbCubeOps.Text;
            string action = CubeOperation.GetOp(ref text, true, false);

            if (CubeOperation.IsReverse(action, op))
            {
                //cancel
                _steps--;
                _sequence = text;
            }
            else
            {
                _steps++;
                _sequence = _sequence + op;
            }
            if (_oneOpDone != null)
            {
                _oneOpDone(op, _sequence, _steps, isSolved);
            }
        }
Beispiel #6
0
        private bool BeforeOp(AnimContext animContext)
        {
            string op = animContext.Op;

            if (op == CubeOperation.UndoOp)
            { //undo
                if (string.IsNullOrEmpty(_sequence))
                {
                    return(false);
                }

                op = CubeOperation.GetOp(ref _sequence, true, true);
                op = CubeOperation.GetReverseOp(op);
                if (!string.IsNullOrEmpty(op))
                {
                    animContext.Op = op;
                }
            }

            CubeSize size  = CubeSize;
            double   edgeX = CubieSize * size.Width / 2;
            double   edgeY = CubieSize * size.Height / 2;
            double   edgeZ = CubieSize * size.Depth / 2;

            if (op == CubeOperation.FoldOp || op == CubeOperation.UnFoldOp)
            {
                bool          unfold = (op == CubeOperation.UnFoldOp);
                FaceTransform f      = new FaceTransform("F", Axis.X, false, new Vector3D(0, edgeY, edgeZ), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? -CubeOperation.PiOver2 : CubeOperation.PiOver2,
                    Begin       = 0,

                    /*
                     * Face = "F",
                     * AxisTranslationFromOrigin = new Vector3D(0, edgeY, edgeZ),
                     * Axis = Axis.X,
                     * IsAxisMoving = false
                     */
                };
                FaceTransform b = new FaceTransform("B", Axis.X, false, new Vector3D(0, edgeY, -edgeZ), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2,
                    Begin       = 0

                                  /*
                                   * Face = "B",
                                   * AxisTranslationFromOrigin = new Vector3D(0, edgeY, -edgeZ),
                                   * Axis = Axis.X,
                                   * IsAxisMoving = false
                                   */
                };
                FaceTransform l = new FaceTransform("L", Axis.Z, false, new Vector3D(-edgeX, edgeY, 0), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? -CubeOperation.PiOver2 : CubeOperation.PiOver2,
                    Begin       = 0,

                    /*
                     * Face = "L",
                     * AxisTranslationFromOrigin = new Vector3D(-edgeX, edgeY, 0),
                     * Axis = Axis.Z,
                     * IsAxisMoving = false
                     */
                };
                FaceTransform r = new FaceTransform("R", Axis.Z, false, new Vector3D(edgeX, edgeY, 0), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2,
                    Begin       = 0

                                  /*
                                   * Face = "R",
                                   * AxisTranslationFromOrigin = new Vector3D(edgeX, edgeY, 0),
                                   * Axis = Axis.Z,
                                   * IsAxisMoving = false
                                   */
                };


                FaceTransform d;
                //if (unfold)
                {
                    d = new FaceTransform("D", Axis.Z, true, new Vector3D(edgeX, -edgeY, 0), new Vector3D(edgeX, edgeY, 0), face => GetFaces(face))
                    {
                        Silent      = true,
                        ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2,
                        Begin       = 0

                                      /*
                                       * Face = "D",
                                       * AxisTranslationFromOrigin = new Vector3D(edgeX, -edgeY, 0),
                                       * Axis2TranslationFromOrigin = new Vector3D(edgeX, edgeY, 0),
                                       * Axis = Axis.Z,
                                       * IsAxisMoving = true
                                       */
                    };
                }
                animContext.TransformParams.Add(f);
                animContext.TransformParams.Add(b);
                animContext.TransformParams.Add(l);
                animContext.TransformParams.Add(r);
                animContext.TransformParams.Add(d);
            }
            else
            {
                if (!CubeOperation.IsValidOp(op))
                {
                    return(false);
                }

                BasicOp basicOp;
                bool    isReverse;
                CubeOperation.GetBasicOp(op, out basicOp, out isReverse);
                CubieTransform transform = new CubieTransform(op, isReverse, basicOp, cn => Cubicles[cn])
                {
                    Silent = animContext.Silent
                };
                transform.ChangeAngle = transform.RotateAngle - animContext.RotatedAngle;
                animContext.TransformParams.Add(transform);
            }


            return(true);
        }