Beispiel #1
0
 // Events
 protected void raiseUpdateForm(RubikCube cube)
 {
     lock (cubeStat)
     {
         cubeStat.fromMatrix(cube.ToMatrix());
     }
 }
Beispiel #2
0
        private void contructViewPoints()
        {
            this.cached = true;

            RubikCube nc = new RubikCube();

            nc = this.Clone();
            int idx = 0;

            for (int y = 0; y <= 3; y++)
            {
                nc.rotateFace(1, 1);
                nc.rotateFace(1, 2);
                nc.rotateFace(1, 3);
                for (int z = 0; z <= 3; z++)
                {
                    nc.rotateFace(2, 1);
                    nc.rotateFace(2, 2);
                    nc.rotateFace(2, 3);
                    this.viewPoints[idx++] = (int[, , ])nc.ToMatrix().Clone();
                }
            }

            for (int x = 0; x <= 3; x++)
            {
                nc.rotateFace(0, 1);
                nc.rotateFace(0, 2);
                nc.rotateFace(0, 3);
                if (x == 0 || x == 2)
                {
                    for (int z = 0; z <= 3; z++)
                    {
                        nc.rotateFace(2, 1);
                        nc.rotateFace(2, 2);
                        nc.rotateFace(2, 3);
                        this.viewPoints[idx++] = (int[, , ])nc.ToMatrix().Clone();
                    }
                }
            }
        }
Beispiel #3
0
        public override bool Equals(Object obj)
        {
            if (!this.cached)
            {
                contructViewPoints();
            }

            RubikCube ToCompare = (RubikCube)obj;

            int[, ,] toCompareMatrix = ToCompare.ToMatrix();

            for (int idx = 0; idx < 24; idx++)
            {
                bool equal = true;

                // Se realiza la comparación. Aunte una incompatibilidad, se cancela.

                int x, y, z;

                for (int i = 0; i < 54 && equal; i++)
                {
                    x = validPositions[i, 0];
                    y = validPositions[i, 1];
                    z = validPositions[i, 2];

                    if (!(viewPoints[idx][x, y, z] == toCompareMatrix[x, y, z] ||        // número igual
                          toCompareMatrix[x, y, z] == 0 || viewPoints[idx][x, y, z] == 0 // comodin
                          ))
                    {
                        equal = false;
                    }
                }
                if (equal)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #4
0
        private void _resolve(RubikCube from, RubikCube to)
        {
            RubikCube working  = from.Clone();
            RubikCube template = new RubikCube();

            template.clear();
            template.ToMatrix()[2, 4, 2] = to.ToMatrix()[2, 4, 2];
            template.ToMatrix()[2, 4, 3] = to.ToMatrix()[2, 4, 3];
            template.ToMatrix()[2, 3, 4] = to.ToMatrix()[2, 3, 4];

            working = this._resolveCross(working, template.Clone());
            if (working != null)
            {
                template.ToMatrix()[1, 4, 2] = to.ToMatrix()[1, 4, 2];
                template.ToMatrix()[0, 3, 2] = to.ToMatrix()[0, 3, 2];

                working = this._resolveCross(working, template.Clone());
                if (working != null)
                {
                    template.ToMatrix()[2, 4, 1] = to.ToMatrix()[2, 4, 1];
                    template.ToMatrix()[2, 3, 0] = to.ToMatrix()[2, 3, 0];

                    working = this._resolveCross(working, template.Clone());
                    if (working != null)
                    {
                        template.ToMatrix()[3, 4, 2] = to.ToMatrix()[3, 4, 2];
                        template.ToMatrix()[4, 3, 2] = to.ToMatrix()[4, 3, 2];

                        working = this._resolveCross(working, template.Clone());
                        if (working != null)
                        {
                            template.ToMatrix()[2, 2, 4] = to.ToMatrix()[2, 2, 4];
                            working = this._resolveCross(working, template.Clone());

                            if (working != null)
                            {
                                template.ToMatrix()[0, 2, 2] = to.ToMatrix()[0, 2, 2];
                                working = this._resolveCross(working, template.Clone());

                                if (working != null)
                                {
                                    template.ToMatrix()[2, 2, 0] = to.ToMatrix()[2, 2, 0];
                                    working = this._resolveCross(working, template.Clone());
                                    if (working != null)
                                    {
                                        template.ToMatrix()[4, 2, 2] = to.ToMatrix()[4, 2, 2];
                                        working = this._resolveCross(working, template.Clone());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.cubeMatch = working;
        }