Пример #1
0
        public CubieColor this[sbyte a1, sbyte a2, sbyte a3]
        {
            get
            {
                CubiePosition position = new CubiePosition(a1, a2, a3);

                foreach (Cubie cubie in cubies)
                {
                    if (cubie.Position.CompareTo(position) == 0)
                    {
                        return(cubie.Color);
                    }
                }
                throw new ApplicationException(String.Format($"Position {position} not found"));
            }

            set
            {
                CubiePosition position = new CubiePosition(a1, a2, a3);

                for (int i = 0; i < cubies.Count; i++)
                {
                    Cubie cubie = cubies[i];
                    if (cubie.Position.CompareTo(position) == 0)
                    {
                        cubie.Color = value;
                        return;
                    }
                }
                throw new ApplicationException(String.Format($"position {position} not found in set"));
            }
        }
Пример #2
0
        public int CompareTo(CubiePosition p)
        {
            if (p.a1 != a1)
            {
                return(a1 - p.a1);
            }

            if (p.a2 != a2)
            {
                return(a2 - p.a2);
            }

            return(a3 - p.a3);
        }
Пример #3
0
        public int CompareTo(Face other)
        {
            for (int i = 0; i < cubies.Count; i++)
            {
                CubiePosition position = cubies[i].Position;

                int ret = cubies[i].Color.CompareTo(other[position.a1, position.a2, position.a3]);

                if (ret != 0)
                {
                    return(ret);
                }
            }

            return(0);
        }
Пример #4
0
        public sbyte Center(bool needPositon)
        {
            foreach (var cubie in cubies)
            {
                CubiePosition cube = cubie.Position;

                if (cube.IsCenter())
                {
                    Debug.Assert(cubie.Color.IsCenter());
                    if (needPositon)
                    {
                        return(cubie.Position.a1);
                    }
                    else
                    {
                        return(cubie.Color.Color);
                    }
                }
            }

            throw new ApplicationException("No center found");
        }
Пример #5
0
        private void ResetFromReader(CubeReader reader)
        {
            for (sbyte side = 0; side < 6; side++)
            {
                Face face = Faces[side];

                face.ResetFromCubeReader(reader, FaceLayout2D.Layout[side], side);
            }

            //adjust the neighbor's color
            for (sbyte side = 0; side < 6; side++)
            {
                Face face = Faces[side];

                foreach (Cubie cube in face.cubies)
                {
                    CubiePosition position = cube.Position;

                    List <sbyte> list = new List <sbyte>();

                    list.Add(position.a1);
                    list.Add(position.a2);
                    list.Add(position.a3);

                    list.Remove(side);

                    sbyte a2 = list[0];
                    sbyte a3 = list[1];

                    cube.Color = new CubieColor(
                        Faces[side][position.a1, position.a2, position.a3].Color,
                        Faces[a2][position.a1, position.a2, position.a3].Color,
                        Faces[a3][position.a1, position.a2, position.a3].Color
                        );
                }
            }
        }