项目作者: adrianosferreira

项目描述 :
A JS implementation of a pathfinding algorithm using BFS (Breadth First Search)
高级语言: JavaScript
项目地址: git://github.com/adrianosferreira/pathfinding.git
创建时间: 2020-05-04T21:20:14Z
项目社区:https://github.com/adrianosferreira/pathfinding

开源协议:

下载


Pathfinding algorithm using BFS

A JS implementation of a pathfinding algorithm using BFS (Breadth-first search) and rendering with HTML Canvas.

Complete stack:

  • HTML
  • JS (ES6)
  • Webpack

Implementation details

The position of each occupied position is stored in an object in the format below:

  1. {
  2. '0,0': 'player',
  3. '1,1': 'tree',
  4. '10,10': 'tree',
  5. '11,7': 'tree',
  6. }

Storing positions this way we obtain time complexity of O(1) for checking a position.

Clicking at any position of the canvas will invoke a breadth-first search algorithm from the start position to the new one outputting the shortest possible distance.

At every step the start position is updated making it possible to change the target at any time and preserving the path already traveled.

Live Demo

https://pathfinding-adriano.herokuapp.com/

Preview

Pathfinding