Project

General

Profile

« Previous | Next » 

Revision eb0369a7

Added by Leszek Koltunski 9 days ago

Phased Solver app: show the moveIndex

View differences:

src/main/java/org/distorted/phasedsolver/SolverActivity.java
15 15
import android.content.SharedPreferences;
16 16
import android.os.Bundle;
17 17
import android.view.View;
18
import android.widget.TextView;
18 19
import android.widget.Toast;
19 20

  
20 21
import androidx.preference.PreferenceManager;
......
40 41
  private InitAssets mAsset;
41 42
  private SharedPreferences mPreferences;
42 43
  private SolverLowerPane mLowerPane;
43

  
44
  private TextView mText;
45
  private SolvedObject mObject;
46
  private int[][] mMoveTable;
47
  private String mMoves;
44 48
///////////////////////////////////////////////////////////////////////////////////////////////////
45 49

  
46 50
  @Override
......
54 58
    OSInterface os = view.getInterface();
55 59
    mAsset = new InitAssets(null, null, os);
56 60
    mLowerPane = new SolverLowerPane(this);
61
    mText = findViewById(R.id.solverMoves);
62
    mMoves = "";
57 63
    }
58 64

  
59 65
///////////////////////////////////////////////////////////////////////////////////////////////////
......
127 133

  
128 134
///////////////////////////////////////////////////////////////////////////////////////////////////
129 135

  
130
  private void solve(PhasedSolver ps, int[] quats, int[][] moveTable)
136
  private void solve(PhasedSolver ps, int[] quats)
131 137
    {
132 138
    int[][] sol = ps.solution(quats);
133 139
    int numPhases = sol.length;
......
157 163
      for(int m=1; m<=numMoves; m++)
158 164
        {
159 165
        int mi = s[m];
160
        moves[index++] = moveTable[mi];
161
        android.util.Log.e("D","move "+m+" : "+moveTable[mi][0]+" "+moveTable[mi][1]+" "+moveTable[mi][2]);
166
        moves[index++] = mMoveTable[mi];
167
        android.util.Log.e("D","move "+m+" : "+mMoveTable[mi][0]+" "+mMoveTable[mi][1]+" "+mMoveTable[mi][2]);
162 168
        }
163 169
      }
164 170

  
......
167 173

  
168 174
///////////////////////////////////////////////////////////////////////////////////////////////////
169 175

  
170
    public void Solve(View v)
176
    private void createObject()
171 177
      {
172 178
      TwistyObject object = getControl().getObject();
173 179

  
......
180 186
      boolean[] r = {true,false,true};
181 187
      boolean[][] rot = {r,r,r};//object.getLayerRotatable(numL);
182 188

  
183
      SolvedObject so = new SolvedObject(pos,axis,angles,cuts,rot);
189
      mObject = new SolvedObject(pos,axis,angles,cuts,rot);
190
      mMoveTable = mObject.getMoveTable();
191
      }
192

  
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

  
195
    public void Solve(View v)
196
      {
197
      if( mObject==null ) createObject();
198

  
199
      TwistyObject object = getControl().getObject();
200
      int[] numL      = object.getNumLayers();
201
      float[][] pos   = object.getCubitPositions(numL);
202

  
184 203
      int numCubits = pos.length;
185 204
      int[] qi = new int[numCubits];
186 205
      for(int i=0; i<numCubits; i++) qi[i] = object.getCubitQuatIndex(i);
187 206

  
188
      int[][] moves = so.getMoveTable();
189

  
190 207
      int[][] whiteCross   = new int[][]{ {12,13,16,17} };
191 208
      int[][] whiteCorners = new int[][]{ {0},{1},{2},{3} };
192 209
      int[][] secondLayer  = new int[][]{ {8},{9},{10},{11} };
......
203 220

  
204 221
      Phase[] phases =
205 222
              {
206
                new PhaseNotCyclic( so, whiteCross),
207
                new PhaseNotCyclic( so, whiteCorners),
208
                new PhaseNotCyclic( so, secondLayer),
209
                new PhaseCyclicOrie1( so, yellowCrossCubit , yellowCrossQuat ),
210
                new PhaseCyclicPerm2( so, yellowCrossCubit , yellowCrossQuat ),
211
                new PhaseRegex( so, regex, yellowCorners ),
223
                new PhaseNotCyclic( mObject, whiteCross),
224
                new PhaseNotCyclic( mObject, whiteCorners),
225
                new PhaseNotCyclic( mObject, secondLayer),
226
                new PhaseCyclicOrie1( mObject, yellowCrossCubit , yellowCrossQuat ),
227
                new PhaseCyclicPerm2( mObject, yellowCrossCubit , yellowCrossQuat ),
228
                new PhaseRegex( mObject, regex, yellowCorners ),
212 229
              };
213 230

  
214
      PhasedSolver ps = new PhasedSolver(so,phases);
231
      PhasedSolver ps = new PhasedSolver(mObject,phases);
215 232

  
216 233
      runOnUiThread(new Runnable()
217 234
        {
218 235
        @Override
219 236
        public void run()
220 237
          {
221
          solve(ps,qi,moves);
238
          solve(ps,qi);
222 239
          }
223 240
        });
224 241
      }
......
230 247
      ObjectControl control = getControl();
231 248
      control.solveObject();
232 249
      mLowerPane.clearMoves(this);
250

  
251
      mMoves = "";
252
      mText.setText(mMoves);
253
      }
254

  
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

  
257
    int findMove(int ax, int row, int angle)
258
      {
259
      int num = mMoveTable.length;
260

  
261
      for( int m=0; m<num; m++)
262
        {
263
        int[] move = mMoveTable[m];
264
        if( ax==move[0] && row==move[1] && angle==move[2] ) return m;
265
        }
266

  
267
      return -1;
268
      }
269

  
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

  
272
    void addMove(int axis, int row, int angle)
273
      {
274
      if( mObject==null ) createObject();
275
      int move = findMove(axis,row,angle);
276
      mMoves += (" "+move);
277
      mText.setText(mMoves);
233 278
      }
234 279

  
235 280
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/phasedsolver/SolverObjectLibInterface.java
11 11

  
12 12
import org.distorted.objectlib.helpers.ObjectLibInterface;
13 13

  
14
import java.lang.ref.WeakReference;
15

  
14 16
///////////////////////////////////////////////////////////////////////////////////////////////////
15 17

  
16 18
public class SolverObjectLibInterface implements ObjectLibInterface
17 19
{
20
  private final WeakReference<SolverActivity> mAct;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
  SolverObjectLibInterface(SolverActivity act) { mAct = new WeakReference<>(act); }
18 25
  public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
19 26
  public void onScrambleEffectFinished() { }
20 27
  public void onBeginRotation() { }
21 28
  public void onSolved() { }
22 29
  public void onObjectCreated(long time) { }
23
  public void onRemoveRotation(int axis, int row, int angle) { }
24 30
  public void failedToDrag() { }
25 31
  public void reportBlockProblem(int type, int place, long pause, long resume, long time) { }
26 32
  public void reportProblem(String problem, boolean reportException) {}
27

  
28 33
  public void onReplaceModeDown(int cubit, int face) { }
29 34
  public void onReplaceModeUp() { }
30 35
  public void reportJSONError(String error, int ordinal) { }
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
  public void onRemoveRotation(int axis, int row, int angle)
40
    {
41
    SolverActivity act = mAct.get();
42
    act.addMove(axis,row,angle);
43
    }
31 44
}
src/main/java/org/distorted/phasedsolver/SolverSurfaceView.java
87 87
      if(!isInEditMode())
88 88
        {
89 89
        SolverActivity act = (SolverActivity)context;
90
        SolverObjectLibInterface ref = new SolverObjectLibInterface();
90
        SolverObjectLibInterface ref = new SolverObjectLibInterface(act);
91 91
        mInterface = new OSInterface(act,ref);
92 92
        mObjectController = new ObjectControl(mInterface);
93 93

  
src/main/res/layout/mainlayout.xml
44 44

  
45 45
    </LinearLayout>
46 46

  
47
    <TextView
48
        android:id="@+id/solverMoves"
49
        android:layout_below="@id/upperBar"
50
        android:layout_width="match_parent"
51
        android:layout_height="60dp"
52
        android:textAppearance="?android:attr/textAppearanceLarge"
53
        android:gravity="center_vertical|start"/>
54

  
47 55
    <LinearLayout
48 56
        android:id="@+id/lowerBar"
49 57
        android:layout_alignParentBottom="true"

Also available in: Unified diff