right now here is my code for a javascript puzzle,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Puzzling Puzzles</title> <link rel="stylesheet" type="text/css" href="../../../CSS/Global.CSS"> <link rel="stylesheet" type="text/css" href="../../../CSS/Code.CSS"> <script language="JavaScript" type="text/javascript"> <!-- var pics = new Array(14); var didUwin = new Array(14); var moveCount=0; var choice; var win=true; var what var where for (var i=0;i<=14;i++) { pics[i]="Pics/"+i+".jpg"; didUwin[i] ="Pics/"+i+".jpg"; } function winCheck() { for(var i=0;i<15;i++) { if(didUwin[i]!=pics[i]) { win=false; return(win); } else { win=true; } } return(win); } function randomPics() { for (var i=0;i<1000;i++) { move((Math.floor(Math.random()*15))) } for (i=0;i<=14;i++) { document.getElementById("a"+i).src=pics[i]; } moveCount=0; document.getElementById("moveCount").value=moveCount; win=false; } function swapSquares(choice) { if (win==false) { move(choice); moveCount++; var i for (i=0;i<=14;i++) { document.getElementById("a"+i).src=pics[i]; } document.getElementById("moveCount").value=moveCount; winCheck() if (win==true) { var answer = confirm("Congradualtions you won with a move count of\n"+moveCount+"\ndo you want to restart") if (answer) {randomPics()} else {return;} } else {return;} } else {} } function move(choice) { if (choice==0||choice==1||choice==4||choice==7||choice==10||choice==13||choice==14)//checks if the blank space is above, below, left, and right { if (pics[choice+1]=="Pics/14.jpg")//checks to the right for blank { pics[choice+1]=pics[choice];//sets current blank to choice pics[choice]="Pics/14.jpg";//sets choice to blank return; } if (pics[choice-1]=="Pics/14.jpg")//checks to left for black { pics[choice-1]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } if (pics[choice-3]=="Pics/14.jpg")//checks below for blank { pics[choice-3]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } if (pics[choice+3]=="Pics/14.jpg")//checks above for blank { pics[choice+3]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } else {} } if (choice==3||choice==6||choice==9||choice==12) { if (pics[choice+1]=="Pics/14.jpg")//checks to the right for blank { pics[choice+1]=pics[choice];//sets current blank to choice pics[choice]="Pics/14.jpg";//sets choice to blank return; } if (pics[choice-3]=="Pics/14.jpg")//checks below for blank { pics[choice-3]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } if (pics[choice+3]=="Pics/14.jpg")//checks above for blank { pics[choice+3]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } else {} } if (choice==2||choice==5||choice==8||choice==11) { if (pics[choice-1]=="Pics/14.jpg")//checks to left for black { pics[choice-1]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } if (pics[choice-3]=="Pics/14.jpg")//checks below for blank { pics[choice-3]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } if (pics[choice+3]=="Pics/14.jpg")//checks above for blank { pics[choice+3]=pics[choice]; pics[choice]="Pics/14.jpg"; return; } else {} } moveCount--; } function identify() { for(var i=0;i<15;i++)//ID what space is incorrect { if(didUwin[i]!=pics[i]) { what = i i = 15 } } for(var i=0;i<15;i++) { if("pics\'+what+'.jpg" == pics[i])//ID where the needed space is { where = i } } alert(what) alert(where) } //--> </script> </head> <body> <table summary="Puzzle" id="puz" align="center"> <tr> <td><input type="image" src="pics\0.jpg" id="a0" onclick="swapSquares(0)"> </td> <td><input type="image" src="pics\1.jpg" id="a1" onclick="swapSquares(1)"> </td> <td><input type="image" src="pics\2.jpg" id="a2" onclick="swapSquares(2)"> </td> </tr> <tr> <td><input type="image" src="pics\3.jpg" id="a3" onclick="swapSquares(3)"> </td> <td><input type="image" src="pics\4.jpg" id="a4" onclick="swapSquares(4)"> </td> <td><input type="image" src="pics\5.jpg" id="a5" onclick="swapSquares(5)"> </td> </tr> <tr> <td><input type="image" src="pics\6.jpg" id="a6" onclick="swapSquares(6)"> </td> <td><input type="image" src="pics\7.jpg" id="a7" onclick="swapSquares(7)"> </td> <td><input type="image" src="pics\8.jpg" id="a8" onclick="swapSquares(8)"> </td> </tr> <tr> <td><input type="image" src="pics\9.jpg" id="a9" onclick="swapSquares(9)"> </td> <td><input type="image" src="pics\10.jpg" id="a10" onclick="swapSquares(10)"> </td> <td><input type="image" src="pics\11.jpg" id="a11" onclick="swapSquares(11)"> </td> </tr> <tr> <td><input type="image" src="pics\12.jpg" id="a12" onclick="swapSquares(12)"> </td> <td><input type="image" src="pics\13.jpg" id="a13" onclick="swapSquares(13)"> </td> <td><input type="image" src="Pics\14.jpg" id="a14" onclick="swapSquares(14)"> </tr> </table> <center> <input type="button" value="Id it" onclick="identify()"> <br> <input type="button" value="Begin" onclick="randomPics()"> <br> <input type="text" readonly="readonly" id="moveCount" value="0" size="1" disabled="disabled"> <br><br><br> <a href="http://validator.w3.org/check?uri=referer"> <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" border=0></a></center> </body> </html>
i the initial puzzle done and now i'm working on an auto solver where you press a button and it solves for one move, right now i'm idenitifying what space is incorrect but i'm having issues with getting the second if statement to work
function identify() { for(var i=0;i<15;i++)//ID what space is incorrect { if(didUwin[i]!=pics[i]) { what = i i = 15 } } for(var i=0;i<15;i++) { if("pics\'+what+'.jpg" == pics[i])//ID where the needed space is { where = i } } alert(what) alert(where) }
link to puzzle without auto solve