vue.js - 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)
}
}
}
}
解决方案
推荐阅读
- java - 仅管理界面上的 Payara 服务器 SSL 错误
- c++ - 轮询 recvfrom(), sendto()
- ignite - 点燃:在缓存中放置 10 次操作时从缓存中删除数据
- python - 为什么一个功能起作用而另一个不起作用?可变性或不变性在这里如何工作?
- c++ - 除法函数返回错误值
- sqlite - 连接到 SQlite 数据库并每天提取信息
- virtualhost - 设置 cloudflare 虚拟主机后 Cloudant 基本身份验证不起作用
- php - Laravel 从数据库中动态填充复选框列表
- jquery - 如何在 th 标签内的 div 标签中垂直对齐文本?
- sql - 查找前一个值的 SQL 脚本,不一定是前一行