Beispiel #1
0
 private Cubie(Cubicle cubicle, string name, Vector3D center, double size)
 {
     _name    = name;
     _cubicle = cubicle;
     _center  = center;
     _size    = size;
 }
 private void Cycle(CubicleOrientation[] cycle)
 {
     try
     {
         if (cycle.Count() < 2)
         {
             return;
         }
         int count = cycle.Count();
         CubicleOrientation fromOrientation = cycle[count - 1];
         Cubicle            fromCubicle     = _getCubicle(fromOrientation.Name);
         Cubie fromCubie = fromCubicle.Cubie;
         Dictionary <string, CubieFace> fromFaces = fromCubicle.CubieFaces;
         if (fromCubie == null)
         {
             Debug.Assert(false);
         }
         for (int i = 0; i < count; i++)
         {
             CubicleOrientation toOrientation = cycle[i];
             Cubicle            toCubicle     = _getCubicle(toOrientation.Name);
             fromCubie       = toCubicle.SetCubie(fromCubie);
             fromFaces       = toCubicle.SetCubieFaces(fromFaces, fromOrientation.OrientationName, toOrientation.OrientationName);
             fromOrientation = toOrientation;
         }
     }
     catch (Exception)
     {
         Debug.Assert(false);
     }
 }
Beispiel #3
0
        public static Cubie CreateCubie(Cubicle cubicle, string name, Vector3D center, double size, IFactory factory)
        {
            Cubie cubie = new Cubie(cubicle, name, center, size);
            //Debug.WriteLine(name);
            Vector3D  c      = center;
            double    offset = size / 2;
            CubieFace face   = null;
            int       i      = 0;

            if (name.IndexOf("U") >= 0)
            {
                c    = center; c.Y += offset;
                face = CubieFace.ConstructCubieFace(cubie, "U", c, size, factory);
                cubie.Faces.Add("U", face);
                cubicle.SetCubieFace("U", face);
            }

            if (name.IndexOf("D") >= 0)
            {
                c    = center; c.Y -= offset;
                face = CubieFace.ConstructCubieFace(cubie, "D", c, size, factory);
                cubie.Faces.Add("D", face);
                cubicle.SetCubieFace("D", face);
            }

            if (name.IndexOf("F") >= 0)
            {
                c    = center; c.Z += offset;
                face = CubieFace.ConstructCubieFace(cubie, "F", c, size, factory);
                cubie.Faces.Add("F", face);
                cubicle.SetCubieFace("F", face);
            }

            if (name.IndexOf("B") >= 0)
            {
                c    = center; c.Z -= offset;
                face = CubieFace.ConstructCubieFace(cubie, "B", c, size, factory);
                cubie.Faces.Add("B", face);
                cubicle.SetCubieFace("B", face);
            }

            if (name.IndexOf("L") >= 0)
            {
                c    = center; c.X -= offset;
                face = CubieFace.ConstructCubieFace(cubie, "L", c, size, factory);
                cubie.Faces.Add("L", face);
                cubicle.SetCubieFace("L", face);
            }

            if (name.IndexOf("R") >= 0)
            {
                c    = center; c.X += offset;
                face = CubieFace.ConstructCubieFace(cubie, "R", c, size, factory);
                cubie.Faces.Add("R", face);
                cubicle.SetCubieFace("R", face);
            }

            return(cubie);
        }
Beispiel #4
0
        public static Cubicle CreateCubicle(string cubicleName, string cubieName, Vector3D center, double size, IFactory factory)
        {
            Cubicle cubicle = new Cubicle(cubicleName, center, size);
            Cubie   cubie   = Cubie.CreateCubie(cubicle, cubieName, center, size, factory);

            cubicle.Cubie = cubie;

            return(cubicle);
        }
Beispiel #5
0
        public static RubiksCube CreateRubiksCube(Vector3D origin, int cubieNum, double cubieSize, OneOpDone oneOpDone, IFactory factory)
        {
            //if(cubieNum!=3) throw new ArgumentException("Invalid CubieNum");
            RubiksCube rubiksCube = new RubiksCube();

            rubiksCube.CubieSize  = cubieSize;
            rubiksCube._model     = factory.CreateModel();
            rubiksCube._oneOpDone = oneOpDone;
            CubeSize size = new CubeSize(cubieNum, cubieNum, cubieNum);

            rubiksCube.CubeSize = size;
            Vector3D start = origin;

            start.X -= (size.Width - 1) * cubieSize / 2;
            start.Y -= (size.Height - 1) * cubieSize / 2;
            start.Z -= (size.Depth - 1) * cubieSize / 2;
            Vector3D min = origin; min.X -= size.Width * cubieSize / 2; min.Y -= size.Height * cubieSize / 2; min.Z -= size.Depth * cubieSize / 2;
            Vector3D max = origin; max.X += size.Width * cubieSize / 2; max.Y += size.Height * cubieSize / 2; max.Z += size.Depth * cubieSize / 2;

            rubiksCube.BoundingBox = new BoundingBox3D(min, max);

            for (int i = 0; i < size.Width; i++)
            {
                for (int j = 0; j < size.Height; j++)
                {
                    for (int k = 0; k < size.Depth; k++)
                    {
                        //if (k == 0 || j == 0) //for debug
                        {
                            Vector3D cubieOri = start;
                            cubieOri.X += i * cubieSize; cubieOri.Y += j * cubieSize; cubieOri.Z += k * cubieSize;
                            string cubicleName = CubeConfiguration.GetCubicleName(size, i, j, k);
                            //Debug.WriteLine(string.Format("({0},{1},{2}): {3}", i,j,k, cubicleName));
                            if (!string.IsNullOrEmpty(cubicleName))
                            {
                                string  cubieName = cubicleName; //solved configuration
                                Cubicle cubicle   = Cubicle.CreateCubicle(cubicleName, cubieName, cubieOri, cubieSize, factory);
                                rubiksCube._cubicles.Add(cubicleName, cubicle);
                            }
                        }
                    }
                }
            }
            return(rubiksCube);
        }
Beispiel #6
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 #7
0
 public CubicleFace(string name, Cubicle cubicle)
 {
     Name     = name;
     _cubicle = cubicle;
 }