Exemplo n.º 1
0
        /// <summary>
        /// Get all cubes in specific row of an specific axis.
        /// </summary>
        /// <param name="axis">axis</param>
        /// <param name="row">row</param>
        /// <returns></returns>
        List <int> SubCubeIndices(RubiksGlobal.TAxis axis, RubiksGlobal.TRow row)
        {
            List <int> indices = new List <int>();

            // define the affected sub cubes
            int[] r_x = { 0, 2 };
            int[] r_y = { 0, 2 };
            int[] r_z = { 0, 2 };
            switch (axis)
            {
            case RubiksGlobal.TAxis.x: r_x[0] = r_x[1] = (int)row; break;

            case RubiksGlobal.TAxis.y: r_y[0] = r_y[1] = (int)row; break;

            case RubiksGlobal.TAxis.z: r_z[0] = r_z[1] = (int)row; break;
            }

            // collect indices of collected sub cubes
            for (int z = r_z[0]; z <= r_z[1]; ++z)
            {
                for (int y = r_y[0]; y <= r_y[1]; ++y)
                {
                    for (int x = r_x[0]; x <= r_x[1]; ++x)
                    {
                        int i = z * 9 + y * 3 + x;
                        indices.Add(_cube_map[i]);
                    }
                }
            }

            return(indices);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shuffle the cube
        /// </summary>
        /// <param name="steps">number of shuffles</param>
        public void Shuffle(int steps)
        {
            var rand = new Random();

            ChangeOperation[] shuffle_ops = new ChangeOperation[steps];
            for (int i = 0; i < steps; ++i)
            {
                RubiksGlobal.TAxis      axis      = RubiksGlobal.TAxis.x;
                RubiksGlobal.TRow       row       = RubiksGlobal.TRow.low;
                RubiksGlobal.TDirection direction = RubiksGlobal.TDirection.left;
                bool valid = false;
                do
                {
                    axis      = (RubiksGlobal.TAxis)rand.Next(0, 2);
                    row       = (RubiksGlobal.TRow)rand.Next(0, 2);
                    direction = (RubiksGlobal.TDirection)rand.Next(0, 1);

                    if (i == 0)
                    {
                        break;
                    }

                    // check if not inverse operation
                    valid = shuffle_ops[i - 1].axis != axis ||
                            shuffle_ops[i - 1].row != row ||
                            shuffle_ops[i - 1].direction == direction;

                    // check if not 3 equal operations in a row
                    if (valid && i > 1)
                    {
                        valid = shuffle_ops[i - 1].axis != axis ||
                                shuffle_ops[i - 1].row != row ||
                                shuffle_ops[i - 1].direction != direction ||
                                shuffle_ops[i - 2].axis != axis ||
                                shuffle_ops[i - 2].row != row ||
                                shuffle_ops[i - 2].direction != direction;
                    }
                }while (valid == false);

                shuffle_ops[i] = new ChangeOperation(axis, direction, row);
            }

            // add change operations to pending queue
            for (int i = 0; i < steps; ++i)
            {
                Change(shuffle_ops[i]);
            }
        }
Exemplo n.º 3
0
 public ChangeOperation(Vector3 rot_axis, int sub_cube_i)
 {
     _axis      = RubiksGlobal.Axis(rot_axis);
     _direction = RubiksGlobal.Direction(rot_axis);
     _row       = RubiksGlobal.Row(_axis, sub_cube_i);
 }
Exemplo n.º 4
0
 public ChangeOperation(RubiksGlobal.TAxis axis, RubiksGlobal.TDirection direction, RubiksGlobal.TRow row)
 {
     _axis      = axis;
     _direction = direction;
     _row       = row;
 }