拼图游戏 算法有问题帮忙更正
<html><head>
<title>拼图游戏---设计者:刘宜彬</title>
</head>
<body>
<script language="javascript">
pos=new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0)
pleft=300
ptop=10
for(i=1;i<17;i++)
{
pleft+=62
if((i-1)%4==0)
{
pleft=300
ptop+=62
}
if (i<16)
{
document.write("<div ID='L"+String(pos[i])+"' STYLE='position:absolute; left:"+pleft+"px; top:"+ptop+"px; width:60px; height:60px; background-color:#00ddff;' onclick='pmove("+pos[i]+",true)'><b><font size=4><center><br><b>"+pos[i]+"</b></center></div>")
}
else
{
document.write("<div ID='L"+String(i)+"' STYLE='position:absolute; left:"+pleft+"px; top:"+ptop+"px; width:0px; height:0px; background-color:#ffddff;' onclick='pmove("+i+")'><b><font size=4><center><br>"+"</center></div>")
}
}
window.status="说明:单击鼠标移动数字"
function pmove(num,zq){
for (i=1;i<17;i++)
{
if (pos[i]==0) Z=i
}
for (i=1;i<17;i++)
{
if (pos[i]==num) M=i
}
if ((Math.abs(Z-M)==1) || (Math.abs(Z-M)==4))
{
T=document.getElementById("L"+String(num)).style.top
L=document.getElementById("L"+String(num)).style.left
document.getElementById("L"+String(num)).style.top=document.getElementById("L"+String(16)).style.top
document.getElementById("L"+String(num)).style.left=document.getElementById("L"+String(16)).style.left
document.getElementById("L"+String(16)).style.top=T
document.getElementById("L"+String(16)).style.left=L
pos[Z]=pos[M]
pos[M]=0
}
if (zq)
{
A=true
for (i=1;i<16;i++)
{
if (pos[i]!=i)
{
A=false
break
}
}
if (A) alert("您成功了!")
}
}
for (ii=1;ii<150;ii++)
{
r=Math.floor(Math.random()*15)+1//1<=r<=15
if (ii<10) r=Math.floor(Math.random()*4)+1+11//12<=r<=15
pmove(r,false)
}
</script>
</body>
</html>