首页 > 解决方案 > Dijkstras 算法 Vue

问题描述

我正在尝试在 vue 中实现 dijkstras 寻路算法。我正在关注https://medium.com/@nicholas.w.swift/easy-dijkstras-pathfinding-324a51eeb0f的伪代码。到目前为止,这是我想出的,但是我正在努力将伪代码翻译成 vue js。我如何能够检查每个节点并将访问的节点从列表中弹出?

Dijkstra() {
      this.unexploredset = [];
      for (let i = 0; i < 16; i++){
        for (let j = 0; j < 16; j++){
          this.nodes[i][j].position = '∞';
          this.nodes[i][j].distance = '∞';
          if(this.nodes[i][j].hasWall == false){
            this.unexploredset.push(this.nodes[i][j])
          }
        }
      }

      let current = this.nodes[3][4];
      let goal = this.nodes[14][14];
      for(let i = 0; i < 255; i++) {
        for (let k = 0; k < 4; k++) {
          if (current.distance <= current.neighbours[k].distance && current.unvisited == true)
          {
            current.unvisited = false;
            let temp = current.neighbours[k];
            current = temp
            this.unexploredset.pop(current);
            current = temp
            if (current == goal)
            {
              console.log("found");
              break
              
            }
            console.log(this.unexploredset.length)
          }
        }
      }
    }

标签: vue.js

解决方案


推荐阅读