Project

General

Profile

« Previous | Next » 

Revision 7f84a768

Added by Leszek Koltunski about 4 years ago

Progress with the 3x3x3 Solver.

Hopefully the only thing that remains to be done is to implement the RubikStateSolver.retCubeString().

View differences:

src/main/java/org/distorted/states/RubikStateSolution.java
31 31

  
32 32
import org.distorted.main.R;
33 33
import org.distorted.main.RubikActivity;
34
import org.distorted.main.RubikPostRender;
34 35
import org.distorted.objects.RubikObject;
36
import org.distorted.patterns.RubikPattern;
35 37

  
36 38
///////////////////////////////////////////////////////////////////////////////////////////////////
37 39

  
38
public class RubikStateSolution extends RubikStateAbstract
40
public class RubikStateSolution extends RubikStateAbstract implements RubikPostRender.ActionFinishedListener
39 41
  {
42
  private static final int DURATION_MILLIS = 750;
43

  
40 44
  private Button mBackButton;
41 45
  private ImageButton mPrevButton, mNextButton;
42 46
  private TextView mMovesText;
47
  private int[][] mMoves;
48
  private int mCurrMove, mNumMoves;
49
  private boolean mCanRotate;
43 50

  
44 51
///////////////////////////////////////////////////////////////////////////////////////////////////
45 52

  
......
99 106
      @Override
100 107
      public void onClick(View v)
101 108
        {
102

  
109
        RubikPostRender post = act.getPostRender();
110
        backMove(post);
111
        mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves));
103 112
        }
104 113
      });
105 114
    }
......
120 129
      @Override
121 130
      public void onClick(View v)
122 131
        {
123

  
132
        RubikPostRender post = act.getPostRender();
133
        makeMove(post);
134
        mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves));
124 135
        }
125 136
      });
126 137
    }
......
137 148
    mMovesText.setLayoutParams(params);
138 149
    mMovesText.setPadding(padding,0,padding,0);
139 150
    mMovesText.setGravity(Gravity.CENTER);
140
    mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
151
    mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves));
141 152
    }
142 153

  
143 154
///////////////////////////////////////////////////////////////////////////////////////////////////
......
161 172
      });
162 173
    }
163 174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177
  private void makeMove(RubikPostRender post)
178
    {
179
    if( mCanRotate )
180
      {
181
      mCurrMove++;
182

  
183
      if( mCurrMove>mNumMoves )
184
        {
185
        mCurrMove= 0;
186
        post.initializeObject(null);
187
        }
188
      else
189
        {
190
        int axis     = mMoves[mCurrMove-1][0];
191
		    int rowBitmap= mMoves[mCurrMove-1][1];
192
		    int bareAngle= mMoves[mCurrMove-1][2];
193
        int angle    = bareAngle*(360/post.getObject().getBasicAngle());
194
        int numRot   = Math.abs(bareAngle);
195

  
196
        if( angle!=0 )
197
          {
198
          mCanRotate = false;
199
          post.addRotation(this, axis, rowBitmap, angle, numRot*DURATION_MILLIS);
200
          }
201
        else
202
          {
203
          android.util.Log.e("solution", "error: solution contains angle 0");
204
          }
205
        }
206
      }
207
    else
208
      {
209
      android.util.Log.e("solution", "failed to make move!");
210
      }
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  private void backMove(RubikPostRender post)
216
    {
217
    if( mCanRotate )
218
      {
219
      mCurrMove--;
220

  
221
      if( mCurrMove<0 )
222
        {
223
        mCurrMove=mNumMoves;
224
        post.initializeObject(mMoves);
225
        }
226
      else
227
        {
228
        int axis     = mMoves[mCurrMove][0];
229
		    int rowBitmap= mMoves[mCurrMove][1];
230
		    int bareAngle= mMoves[mCurrMove][2];
231
        int angle    = bareAngle*(360/post.getObject().getBasicAngle());
232
        int numRot   = Math.abs(bareAngle);
233

  
234
        if( angle!=0 )
235
          {
236
          mCanRotate = false;
237
          post.addRotation(this, axis, rowBitmap, -angle, numRot*DURATION_MILLIS);
238
          }
239
        else
240
          {
241
          android.util.Log.e("solution", "error: solution contains angle 0");
242
          }
243
        }
244
      }
245
    else
246
      {
247
      android.util.Log.e("solution", "failed to back move!");
248
      }
249
    }
250

  
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

  
253
  void setupMoves(final RubikActivity act, int numMoves, String moves)
254
    {
255
    android.util.Log.e("solution", "got "+numMoves+" moves: "+moves);
256

  
257
    mCanRotate= true;
258
    mCurrMove = 0;
259
    mNumMoves = numMoves;
260
    mMoves    = new int[mNumMoves][3];
261

  
262
    RubikPattern.parseMoves(mMoves,numMoves,moves);
263

  
264
    mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves));
265
    }
266

  
164 267
///////////////////////////////////////////////////////////////////////////////////////////////////
165 268

  
166 269
  public void savePreferences(SharedPreferences.Editor editor)
......
177 280
    {
178 281

  
179 282
    }
283

  
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

  
286
  public void onActionFinished(final long effectID)
287
    {
288
    mCanRotate = true;
289
    }
180 290
  }

Also available in: Unified diff