We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I have worked on a Rubik's Cube Simulator since months and I try to make work my solver but it crash the sketch every time and work once out of 6 times and I've no idea what is exactly the problem so here the code:
void solve(String method){//method used to solve the Rubik's cube solverStat = "inspecting ..."; if(!rc.isSolved()){ println(rc.codeString()); if(method.toLowerCase()=="undo" || method.toLowerCase() == solvingMethod[0]){//robot's method while(!rc.isSolved()){//tant que le cube n'est pas résolue l'IA undo les mouvementss undo(); } }else if(method.toLowerCase()=="beginner" || method.toLowerCase()=="lbl" || method.toLowerCase() == solvingMethod[1]){//Beginner's method //Cube scanning to find cubies int[] UFpos = getCubie("UF"), URpos = getCubie("UR"), UBpos = getCubie("UB"), ULpos = getCubie("UL"); if(UFpos[0]>=3) UFpos = getCubie("FU");//if the cubie isn't in/on the cube //indicate the position of the desired cubies solverStat = "searching solution ...\nUF("+UFpos[0]+", "+UFpos[1]+", "+UFpos[2]+"), UR("+URpos[0]+", "+URpos[1]+", "+URpos[2]+"), UB("+UBpos[0]+", "+UBpos[1]+", "+UBpos[2]+"), UL("+ULpos[0]+", "+ULpos[1]+", "+ULpos[2]+")"; println(solverStat);//display the solver's stat //UF println("UF is at: "+UFpos[0]+", "+UFpos[1]+", "+UFpos[2]); whoIs("UF");//At which place the UF cubie is if(!cubieInPlace("UF")){//If this cubie isn't in place solverStat = "placing UF"; if(cubieIsOriented("UF")){//good edge //cf fiche if(UFpos[0]==1 && UFpos[1]==0 && UFpos[2]==2) moveStr = "FF";//MDDm else if(UFpos[0]==0 && UFpos[1]==1 && UFpos[2]==2) moveStr = "F"; else if(UFpos[0]==2 && UFpos[1]==1 && UFpos[2]==2) moveStr = "f"; else if(UFpos[0]==0 && UFpos[1]==0 && UFpos[2]==1) moveStr = "DFF"; else if(UFpos[0]==2 && UFpos[1]==0 && UFpos[2]==1) moveStr = "dFF"; }else{//bad edge (wrong orientation) if(UFpos[0]==1 && UFpos[1]==0 && UFpos[2]==2) moveStr = "DMdm";//dMDm else if(UFpos[0]==0 && UFpos[1]==1 && UFpos[2]==2) moveStr = "Ulu"; else if(UFpos[0]==2 && UFpos[1]==1 && UFpos[2]==2) moveStr = "uRU"; else if(UFpos[0]==0 && UFpos[1]==0 && UFpos[2]==1) moveStr = "lFl"; else if(UFpos[0]==2 && UFpos[1]==0 && UFpos[2]==1) moveStr = "Rfr"; else if(UFpos[0]==1 && UFpos[1]==2 && UFpos[2]==2) moveStr = "FuRU";//fUlu or FFDMdm or ffdMDm } }else rc.rotU();//Y algorithm = moveStr;moveStrValid = true;//moves validation }else if(method.toLowerCase()=="fridrich" || method.toLowerCase()=="cfop" || method.toLowerCase() == solvingMethod[2]){//speedcuber's method }else if(method.toLowerCase()=="petrus" || method.toLowerCase() == solvingMethod[3]){//... }else if(method.toLowerCase()=="roux" || method.toLowerCase() == solvingMethod[4]){ }else if(method.toLowerCase()=="edgefirst" || method.toLowerCase() == solvingMethod[5]){ }else if(method.toLowerCase()=="cornerfirst" || method.toLowerCase() == solvingMethod[6]){ }else if(method.toLowerCase()=="zz" || method.toLowerCase() == solvingMethod[7]){ }else if(method.toLowerCase()=="vh" || method.toLowerCase() == solvingMethod[8]){ }else if(method.toLowerCase()=="m2 3op" || method.toLowerCase() == solvingMethod[9]){//BLD method for speedcubers }else{ println("the method selected to solve the cube isn't available for the moment.\nThe methods available are: "+solvingMethod);//indique que la méthode choisi n'est pas disponible et celles disponibles } }else{//If the cube is solved, it anounce it solverStat = "cube solved"; fill(255, 0, 0); textSize(24); text("Solved", 60, height/2); save("data/cubeStyle-"+cubeStyleSelected+".png"); } println(solverStat); } String[][][] getCubiePos(int[] fpos, String code){ String[][][] gpos = {{{code}}}; gpos[fpos[0]][fpos[1]][fpos[2]] = code; return gpos; } void whoIs(String ccode){//who is the cubie if(cubieInPlace(ccode)) println(ccode+" is in is place"); else println(ccode+" is in the place of "+rc.grid[getCubie(ccode)[0]][getCubie(ccode)[1]][getCubie(ccode)[2]].code); } String[][][] findCubie(String ccode){ int[] pos = {0}; String[][][] cpos; for(int x=0; x<3; x++){ for(int y=0; y<3; y++){ for(int z=0; z<3; z++){ //int[][][] pos = {x{y{z}}}; if(rc.grid[x][y][z].code.equals(ccode)){pos[0] = x; pos[1] = y; pos[2] = z;} } } } cpos = getCubiePos(pos, ccode); return cpos; } int[] getCubie(String code){//scan to find the cubie that has the code int x=findCubieX(code), y=findCubieY(code), z=findCubieZ(code); String[] ncode; if(x>=3||x<0){//If the cubie is inexistant or out of the cube String tmp; ncode = split(code, ""); if(ncode.length==2){tmp=ncode[0];ncode[0]=ncode[1];ncode[1]=tmp;} else{tmp=ncode[2];ncode[2]=ncode[1];ncode[1]=ncode[0];ncode[0]=tmp;} code = join(ncode, ""); x=findCubieX(code); y=findCubieY(code); z=findCubieZ(code); } if(x>=3||x
And the dead line is the 21 of may (this month).
Please help me, I've asked to anyone who knows about programming and Processing but non of them could help. So I'll appreciate your help.
Answers
we can't run the code since it is not complete
you wrote:
what happens exactly? which line? You should mark the important part
also you need to explain what the concept is
long parts above are commented out with /* */ so why post them?
comments are in French, better use English
I don't know what "crash the sketch" means either. You should be a bit more precise.
I see an obvious error. See String. Don't compare strings with ==.
Ho yes sorry guys: here is it:
@Chrisir: it doesn't show which line is problematic, btw I've translated all into english (I had to put it in french because it's required). The concept of the solver is that it allows the computer to solve the Rubik's cube in it current state with the possibility to change the method, in all case the rules of the AI is to search a desired cubie than depending on the position and the orientation of this cubie it will apply a specific algorithm to solve the cubie and do that for every cubie unteal it has solved the Rubik's cube
@PhiLho where's the error ? Is this for debugging or what ?
line 5, 9, 38, 40 ... everywhere ;-)
as he wrote: every string must be compared with equals -- never use == for string pls
line 38, 40 ? It's correct. What's the difference between foo.toLowerCase().equals("foo") and foo.toLowerCase() == "foo" ?
== doesn't work with string
equals works
try it with philhos example
Okay, I understand now this glichy problem but it doesn't solve the main problem
this occurs very often in your code...
i'm referring to the 1st post
also in line 39,41 etc. nothing happens, there is a long if condition and then nothing between { and }
I don't understand this...
I can't help you with that anyway since I don't know how to solve the cube. I'm sorry.
:-S :-S :-S
"where's the error ?"
Have you tried to run the code I shown? One line is missing, the one where the result of toLowerCase() is compared with ==
If your code is faulty at something as fundamental as this, there is no point in trying to fix something else, until this is OK, at least.
@Chrisir: l.39-41 is a placeholder for the next solving methods but first LbL has to work than I'll work on the next ones. @PhiLho yes I've ran it and saw the error and I've corrected all the conditions comparing strings but the problem isn't solved yet :-( So now, let's see other things
crash
you wrote it crashes
but you don't know where
but we can't run your code.
please post your entire code so we can run it (or somebody else who knows the topic)
also you just can place println("1"); println("2"); println("3"); and thus see how far he goes until he crashes (or write to textfile when he really crashes hard)
this line
this line alone
if(method.toLowerCase()=="beginner" || method.toLowerCase()=="lbl" || method.toLowerCase() == solvingMethod[1]){
looks strange to me. Why not unify those?
Why not use method = method.toLowerCase(); once and not 30 times?
Why not use switch (method) { ?
Why not unify beginner / lbl / solvingMethod[1] to one?
solver
did you search the forum for rubick' s cube or so? There was another thread some weeks ago
here
http://forum.processing.org/two/discussion/2493/how-to-simulate-a-rubiks-cube/p1
@Chrisir: good idea an btw here's the entire code:
why don't you ask the guy from the other thread?
@Chrisir: okay, but do you see other errors ?
@asimes can you help me ?
There is too much code to look for an unknown error, can you try to isolate it?
Okay:
So ?
When I said try to identify the unknown error I meant describe when / why it happens. I'm not going to spend hours looking through code when I don't know what I'm looking for
honestly the code is too long, the topic too complex and your description of your problem / error too vague. I don't think anybody here has a few hours to spend
either you offer money here (job opportunity)
or you find a more experienced fellow student at your university
that is not meant as a offence, just an advice
you could go to eclipse where you can better debug
you could invent more println too see what's going on in your code and where the error lies
you could describe your error more precise to asimes
you could make test configurations like clean cube plus row 1 is off by one
then test: does the solving work? ok.
next: clean cube row 2
row 3
column 1
column 2
col 3
etage 1,2,3
now go over to more complex configs - thus you can find what's wrong.
;-)
i mean when you want help
make comments in english not french
explain how it works (I asked that weeks ago)
explain what UF UL etc. means
in short : ask a fellow student
Okay:
The problem is that when the solver use Undo method it undo only one move and a bad one, when it's Beginner's method the AI is unable to execute the desired algorithms depending on the cubies' positions but the scanning is done so the code goes well until the execution