计算量大 , 可以用setTimeout 来设置 多少时间后在运行,,这样是最好的防止 程序因计算量大,而导致死机。

解决方案 »

  1.   

    楼主这纯粹就是看不起JS,以为它只是一门小脚本语言JS跟其它的程序语言一样,某些地方,还超过了某些较流行的语言,只是它的出身,注定了有些局限性.神经网络算法算个球.这个跟本与语种无关的..这个只能说,你对JS实在是太不了解了.
      

  2.   

    A* pathfinding
    http://bbs.blueidea.com/thread-2664629-1-1.html蚁群
    http://bbs.blueidea.com/viewthread.php?tid=2539054&page=
      

  3.   

    LZ够恨,一个笑话要骗一个网络圣经算法,
    PS:嘛是网络圣经算法?实现目标是什么?
      

  4.   

    直接复制、粘贴看效果
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>最短路径算法</title>
    <style>
    BODY {
    background-color:buttonFace;font-size:12px; scrollbar-3dlight-color:616161;
            scrollbar-arrow-color:888888;
            scrollbar-base-color:buttonFace;
            scrollbar-face-color:buttonFace;
            scrollbar-highlight-color:ffffff;
            scrollbar-shadow-color:595959;
            scrollbar-darkshadow-color:FFFFFF;
    }A:link {
    COLOR: blue; FONT-FAMILY: "宋体"; TEXT-DECORATION: none
    }
    A:visited {
    COLOR: blue; TEXT-DECORATION: none
    }
    A:active {
    COLOR: #6699ff; TEXT-DECORATION: none
    }
    A:hover {
    COLOR: #ed5350; TEXT-DECORATION: none
    }
    td{font-size:12px}
    </style>
    </head>
    <body>
    <!-- Code Begin -->
    <script language="JavaScript">
    var mstr = [
    "**********************",
    "*    S               *",
    "*                    *",
    "*        *   *** *** *",
    "*        *           *",
    "**  ********         *",
    "*    *               *",
    "*    *    *          *",
    "*    *    *  *********",
    "*         *          *",
    "*        ********    *",
    "* ****** *           *",
    "*        *    ***    *",
    "*        *           *",
    "*   **  ***      *****",
    "*         *          *",
    "*  ****** *****    ***",
    "*  *    *            *",
    "*  * *  *    *   N   *",
    "*    *               *",
    "**********************"
    ];
    for(j=0;j<mstr.length;j++)
      mstr[j]=mstr[j].split("");
    var nnx,nny,ssx,ssy;
    function ptClass(marr,pg,nx,ny,sx,sy)
    {
      this.marr=marr;
      this.pg=pg;
      this.nx=nx;
      this.ny=ny;
      this.sx=sx;
      this.sy=sy;
      this.bjw;
      this.rv={};
      this.zj=[];
      this.zjb=[];
    }
    ptClass.prototype.TX = [ 1, 0,-1, 0];
    ptClass.prototype.TY = [ 0, 1, 0,-1];ptClass.prototype.getptyl = function ()
    {
      this.rv[this.nx+":"+this.ny]="N";
      this.zj[0]=[this.nx,this.ny];
      if(!this.gotl()) return null;
      var rearr=[];
      var dd = this.bjw;
      while(this.rv[dd]!="N")
      {
        rearr[rearr.length]=dd.split(":");
        dd=this.rv[dd];
      }
      return rearr;
    }
    ptClass.prototype.gotl = function ()
    {
      this.zjb=[];
      for(var ii=0; ii<this.zj.length; ii++)
      {
        var fr = this.zj[ii];
        var vs = fr[0]+":"+fr[1];
        for(var p=0; p<4; p++)
        {
          var x = fr[0]+this.TX[p];
          var y = fr[1]+this.TY[p];
          if(x==this.sx && y==this.sy)
          {
            this.bjw = vs;
            return true;
          }
          var zb = x+":"+y;
          if(this.marr[y][x]==this.pg && !this.rv[zb])
          {
            this.rv[zb] = vs;
            this.zjb[this.zjb.length] = [x,y];
          }
        }
      }
      this.zj=this.zjb;
                             this.yan();
      if(this.zj.length>0)
        return this.gotl();
      else
        return false;
    }
    ptClass.prototype.yan = function ()
    {
      for(var ii=0; ii<this.zj.length; ii++)
      {
        var t = this.zj[ii];
        maptt.rows[t[1]].cells[t[0]].style.backgroundColor = "#CC66FF";
      }
      alert("停一下!");
    }
    function sou()
    {
      var k = new ptClass(mstr," ",nnx,nny,ssx,ssy);
      var a = k.getptyl();
      if(a==null)
      {
        alert("道路不通!");
        return;
      }
      for(var ii=0; ii<a.length; ii++)
      {
        var t = a[ii];
        maptt.rows[t[1]].cells[t[0]].style.backgroundColor = "#ffff00";
      }
    }
    </script>
    <table id="maptt" cellspacing="1" cellpadding="0" border="0" bgcolor="#000000">
    <script>
    var ntw = mstr[0].length;
    var nth = mstr.length;
    for(j=0;j<nth;j++)
    {
      document.write("<tr>");
      for(i=0;i<ntw;i++)
      {
        var sn = "#ffffff";
        switch(mstr[j][i])
        {
         case "*": sn = "#cccccc";
          break;
         case "N": sn = "#0000ff";
          nnx=i; nny=j;
          break;
         case "S": sn = "#ff0000";
          ssx=i; ssy=j;
          break;
        } 
        document.write('<td style="background-color:'+sn+'" width="20" height="20"></td>');
      }
      document.write("</tr>");
    }
    </script>
    </table>
    <input type="button" value="查找路径" onclick="sou()">
    <!-- Code Over -->
    </body>
    </html>