Skip to content

Conversation

kounoike
Copy link
Contributor

@kounoike kounoike commented Jan 12, 2025

undocumented but usefule range parameter.

import { findPath } from 'game/utils'

export function loop() {
  const path1 = findPath({ x: 5, y: 10 }, { x: 10, y: 10 })
  console.log(`path1.length: ${path1.length}`)
  for (let idx = 0; idx < path1.length; idx++) {
    const pos = path1[idx]
    console.log(`path1[${idx}]: ${pos.x}, ${pos.y}`)
  }

  const path2 = findPath({ x: 5, y: 10 }, { x: 10, y: 10 }, { range: 3 })
  console.log(`path2.length: ${path2.length}`)
  for (let idx = 0; idx < path2.length; idx++) {
    const pos = path2[idx]
    console.log(`path2[${idx}]: ${pos.x}, ${pos.y}`)
  }
}

shows

path1.length: 5
path1[0]: 6, 10
path1[1]: 7, 10
path1[2]: 8, 10
path1[3]: 9, 9
path1[4]: 10, 10
path2.length: 2
path2[0]: 6, 10
path2[1]: 7, 10
path1.length: 5
path1[0]: 6, 10
path1[1]: 7, 10
path1[2]: 8, 10
path1[3]: 9, 9
path1[4]: 10, 10
path2.length: 2
path2[0]: 6, 10
path2[1]: 7, 10

so, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant