Project

General

Profile

« Previous | Next » 

Revision 5043d5d0

Added by Leszek Koltunski about 3 years ago

Refactor the automatic scrambling. From now on, it is not needed to care about single and double turns when randomizing a new turn.

View differences:

src/main/java/org/distorted/objects/TwistyDino4.java
66 66

  
67 67
///////////////////////////////////////////////////////////////////////////////////////////////////
68 68

  
69
  public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow,
70
                                   int numScramble, int remScrambles, int remDoubleScrambles)
69
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
71 70
    {
72
    if( numScramble==1 )
71
    if( num==0 )
73 72
      {
74
      scramble[0] = rnd.nextInt(ROTATION_AXIS.length);
73
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
74
      scramble[num][1] = (scramble[num][0]==1 || scramble[num][0]==2) ? 0:2;
75 75
      }
76 76
    else
77 77
      {
78 78
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
79
      scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
79
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
80
      scramble[num][1] = scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1];
80 81
      }
81 82

  
82
    scramble[1] = (numScramble==1) ? ((scramble[0]==1 || scramble[0]==2) ? 0:2) : (oldRotAxis+scramble[0]==3 ? 2-oldRow : oldRow);
83

  
84
    int random = rnd.nextInt(remScrambles);
85
    int result = random<remDoubleScrambles ? 2:1;
86
    int sign   = rnd.nextInt(2);
87

  
88
    scramble[2] = sign==0 ? result : -result;
83
    switch( rnd.nextInt(2) )
84
      {
85
      case 0: scramble[num][2] = -1; break;
86
      case 1: scramble[num][2] =  1; break;
87
      }
89 88
    }
90 89

  
91 90
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff