예제 #1
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]);
            }
        }
예제 #2
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);
 }
예제 #3
0
 public ChangeOperation(RubiksGlobal.TAxis axis, RubiksGlobal.TDirection direction, RubiksGlobal.TRow row)
 {
     _axis      = axis;
     _direction = direction;
     _row       = row;
 }