I am producing a Rubik's Cube scramble generator which creates a string of 17-18 moves/members. Basically, I'm putting a for loop for getting one move each time; 18 times. In the second function (static String printMove()), I have used java.util.Random to give a new move every time. However, the first move is random, after which all the other 17 members/moves are null. I rechecked it and can't understand where I am going wrong.
Here's my code, if anyone could help. I really needed help on this since I thought of creating a GUI based on this simple system later but can't get the basics itself.
import java.util.*;
class Gen
{
public static void main()
{
String scramble[]=new String[18];
for(int x=0;x<=17;x++)
{
scramble[0]=printMove();
}
String sc=Arrays.toString(scramble);
System.out.println(sc);
}
public static String printMove()
{
String moves[]={"","","R","R\'","R2","U","U\'","U2","F","F\'","F2","L","L\'","L2","D","D\'","D2","B","B\'","B2"};
String move="";
Random r=new Random();
int ch=r.nextInt(19)+1;
switch(ch)
{
case 1:
move=moves[ch];
break;
case 2:
move=moves[ch];
break;
case 3:
move=moves[ch];
break;
case 4:
move=moves[ch];
break;
case 5:
move=moves[ch];
break;
case 6:
move=moves[ch];
break;
case 7:
move=moves[ch];
break;
case 8:
move=moves[ch];
break;
case 9:
move=moves[ch];
break;
case 10:
move=moves[ch];
break;
case 11:
move=moves[ch];
break;
case 12:
move=moves[ch];
break;
case 13:
move=moves[ch];
break;
case 14:
move=moves[ch];
break;
case 15:
move=moves[ch];
break;
case 16:
move=moves[ch];
break;
case 17:
move=moves[ch];
break;
case 18:
move=moves[ch];
break;
case 19:
move=moves[ch];
break;
}
return move;
}
}
Aucun commentaire:
Enregistrer un commentaire