Project

General

Profile

« Previous | Next » 

Revision a96b9267

Added by Leszek Koltunski about 1 month ago

minor

View differences:

src/main/java/org/distorted/phasedsolver/SolverActivity.java
18 18
import androidx.preference.PreferenceManager;
19 19

  
20 20
import org.distorted.library.main.DistortedLibrary;
21
import org.distorted.library.type.Static3D;
22
import org.distorted.objectlib.algsolvers.PhasedSolver;
23
import org.distorted.objectlib.algsolvers.SolvedObject;
21 24
import org.distorted.objectlib.main.InitAssets;
22 25
import org.distorted.objectlib.main.ObjectControl;
26
import org.distorted.objectlib.main.TwistyObject;
23 27
import org.distorted.objectlib.metadata.ListObjects;
24 28
import org.distorted.os.OSInterface;
25 29

  
......
29 33
{
30 34
    private InitAssets mAsset;
31 35
    private SharedPreferences mPreferences;
36
    private SolverLowerPane mLowerPane;
32 37

  
33 38
///////////////////////////////////////////////////////////////////////////////////////////////////
34 39

  
......
42 47
      SolverSurfaceView view = findViewById(R.id.solverView);
43 48
      OSInterface os = view.getInterface();
44 49
      mAsset = new InitAssets(null,null,os);
50
      mLowerPane = new SolverLowerPane(this);
45 51
      }
46 52

  
47 53
///////////////////////////////////////////////////////////////////////////////////////////////////
......
84 90

  
85 91
///////////////////////////////////////////////////////////////////////////////////////////////////
86 92

  
87
    private ObjectControl getControl()
93
    ObjectControl getControl()
88 94
      {
89 95
      SolverSurfaceView view = findViewById(R.id.solverView);
90 96
      return view.getObjectControl();
......
117 123

  
118 124
    public void Reset(View v)
119 125
      {
120

  
126
      ObjectControl control = getControl();
127
      control.solveObject();
128
      mLowerPane.clearMoves(this);
121 129
      }
122 130

  
123 131
///////////////////////////////////////////////////////////////////////////////////////////////////
124 132

  
125 133
    public void Solve(View v)
126 134
      {
127

  
135
      TwistyObject object = getControl().getObject();
136

  
137
      int[] numL      = object.getNumLayers();
138
      float[][] pos   = object.getCubitPositions(numL);
139
      Static3D[] axis = object.getRotationAxis();
140
      int[][] angles  = object.getBasicAngles();
141
      float[][] cuts  = object.getCuts(numL);
142
      boolean[][] rot = object.getLayerRotatable(numL);
143

  
144
      SolvedObject so = new SolvedObject(pos,axis,angles,cuts,rot);
145
      int numCubits = pos.length;
146
      int[] qi = new int[numCubits];
147
      for(int i=0; i<numCubits; i++) qi[i] = object.getCubitQuatIndex(i);
148

  
149
      int[][] moves = so.getMoveTable();
150

  
151
      int[][] params = {{12,13,16,17}};
152
      int[] modes  = { PhasedSolver.MODE_ALL_AT_ONCE_OP };
153
      PhasedSolver ps = new PhasedSolver(so,params,modes);
154

  
155
      runOnUiThread(new Runnable()
156
        {
157
        @Override
158
        public void run()
159
          {
160
          int[][] sol = ps.solution(qi);
161
          int numPhases = sol.length;
162
          android.util.Log.e("D", "Solution, num of phases: "+numPhases);
163

  
164
          for(int p=0; p<numPhases; p++)
165
            {
166
            int numMoves = sol[p]==null ? -1 : sol[p].length;
167
            android.util.Log.e("D", "Phase "+p+" numMoves="+numMoves);
168

  
169
            for(int m=0; m<numMoves; m++)
170
              {
171
              android.util.Log.e("D", "move "+m+" : "+sol[p][m]);
172
              }
173
            }
174
          }
175
        });
128 176
      }
129 177

  
130 178
///////////////////////////////////////////////////////////////////////////////////////////////////
131 179

  
132 180
    public void Left(View v)
133 181
      {
134

  
182
      mLowerPane.backMove(this);
135 183
      }
136 184

  
137 185
///////////////////////////////////////////////////////////////////////////////////////////////////
138 186

  
139 187
    public void Right(View v)
140 188
      {
141

  
189
      mLowerPane.makeMove(this);
142 190
      }
143 191
}
src/main/java/org/distorted/phasedsolver/SolverLowerPane.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.phasedsolver;
11

  
12
import android.widget.TextView;
13

  
14
import org.distorted.objectlib.helpers.MovesFinished;
15
import org.distorted.objectlib.main.ObjectControl;
16

  
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18

  
19
public class SolverLowerPane implements MovesFinished
20
{
21
  private static final int MOVES_PLACE_0 = 100;
22
  private static final int MOVES_PLACE_1 = 101;
23
  private static final int MILLIS_PER_DEGREE = 6;
24

  
25
  private int[][] mMoves;
26
  private int mNumMoves;
27
  private int mCurrMove;
28
  private boolean mCanMove;
29
  private final TextView mText;
30
  private ObjectControl mControl;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
  SolverLowerPane(SolverActivity act)
35
    {
36
    mText = act.findViewById(R.id.solverText);
37
    mCanMove = true;
38
    setMoves(act,null);
39
    }
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
  private void setText(SolverActivity act)
44
    {
45
    act.runOnUiThread(new Runnable()
46
      {
47
      @Override
48
      public void run()
49
        {
50
        mText.setText((mCurrMove+1)+"/"+mNumMoves);
51
        }
52
      });
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  void setMoves(SolverActivity act, int[][] moves)
58
    {
59
    mMoves    = moves;
60
    mNumMoves = moves==null ? 0 : moves.length;
61
    mCurrMove = moves==null ?-1 : 0;
62

  
63
    setText(act);
64
    }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  void clearMoves(SolverActivity act)
69
    {
70
    setMoves(act,null);
71
    }
72

  
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

  
75
  void backMove(SolverActivity act)
76
    {
77
    if( mCanMove && mCurrMove>0 )
78
      {
79
      mCanMove = false;
80
      mCurrMove--;
81
      setText(act);
82

  
83
      int[] move = mMoves[mCurrMove];
84

  
85
      mControl = act.getControl();
86
      mControl.blockTouch(MOVES_PLACE_0);
87
      mControl.addRotation(this, move[0], (1<<move[1]), -move[2], MILLIS_PER_DEGREE);
88
      }
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
  void makeMove(SolverActivity act)
94
    {
95
    if( mCanMove && mCurrMove<mNumMoves-1 )
96
      {
97
      mCanMove = false;
98
      mCurrMove++;
99
      setText(act);
100

  
101
      int[] move = mMoves[mCurrMove];
102

  
103
      mControl = act.getControl();
104
      mControl.blockTouch(MOVES_PLACE_1);
105
      mControl.addRotation(this, move[0], (1<<move[1]), move[2], MILLIS_PER_DEGREE);
106
      }
107
    }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
  public void onActionFinished(final long effectID)
112
    {
113
    mCanMove = true;
114
    mControl.unblockRotation();
115
    }
116
}
src/main/res/layout/mainlayout.xml
66 66
            android:id="@+id/solverText"
67 67
            android:layout_width="0dp"
68 68
            android:layout_height="match_parent"
69
            android:layout_weight="4.0"/>
69
            android:layout_weight="5.0"
70
            android:gravity="center"
71
            android:textSize="40sp"/>
70 72

  
71 73
        <ImageButton
72 74
            android:id="@+id/solverRight"

Also available in: Unified diff