index.js
// returns the length of the path
returns the length of the path
returns the length of the path
findPath(start, end, path) {
    let pathLength = 0
    const frontier = [ start ]
    const came_from = {}
    came_from[start.id] = start.id
    while (frontier.length) {
      let current = frontier.shift()
      if (current.id === end.id) {
        current = end
        while (current !== start.id) {
          current = came_from[current.id]
          pathLength += 2
        }
        return
      }
      for (let id in current.to) {
        const next = current.to[id]
        if (came_from[id] === undefined) {
          frontier.push(next)
          came_from[id] = current
        }
      }
    }
    return pathLength
  }
findPath ( start , end , path ) { let pathLength = 0 const frontier = [ start ] const came_from = { } came_from [ start . id ] = start . id while ( frontier . length ) { let current = frontier . shift ( ) if ( current . id === end . id ) { current = end while ( current !== start . id ) { current = came_from [ current . id ] pathLength += 2 } return } for ( let id in current . to ) { const next = current . to [ id ] if ( came_from [ id ] === undefined ) { frontier . push ( next ) came_from [ id ] = current } } } return pathLength }
returns the length of the path
returns the length of the path
// TODO: store portals in came_from // record the path //path[pathLength] = x //path[pathLength+] = y