Giter Club home page Giter Club logo

astarnim's People

Contributors

bitdeli-chef avatar nycto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

astarnim's Issues

"Cannot instantiate error"

The example works for me, but when I try the following code, I get a "cannot instantiate path" error, and I really can't figure out why.

import strformat
import astar


const
  Up* = (x: 0, y: 1, z: 0)
  Down* = (x: 0, y: -1, z: 0)
  West* = (x: -1, y: 0, z: 0)
  East* = (x: 1, y: 0, z: 0)
  South* = (x: 0, y: 0, z: 1)
  North* = (x: 0, y: 0, z: -1)

  directions* = [Up, Down, West, East, South, North]

type GNode* = object
  x: int
  y: int
  z: int

type Grid* = seq[seq[seq[GNode]]]

proc `$`(g: Grid): string =
  let h = g.len
  let l = g[0].len
  let w = g[0][0].len
  result = "({w=}, {h=}, {l=})".fmt

proc `$`(gn: GNode): string = "({gn.x=}, {gn.y=}, {gn.z=})".fmt

proc newGrid(): Grid =
  result = @[]
  for y in 0..4:
    var plane = newSeq[seq[GNode]]()
    for z in 0..4:
      var row = newSeq[Gnode]()
      for x in 0..4:
        let gnode = GNode(x: x, y: y, z: z)
        row.add(gnode)
      plane.add(row)
    result.add(plane)

iterator neighbors*(g: Grid, n: GNode): Gnode =
  for dir in directions:
    let x = n.x + dir.x
    let y = n.y + dir.y
    let z = n.z + dir.z
    let h = g.len
    let l = g[0].len
    let w = g[0][0].len
    if (y in 0..<h):
      if (z in 0..<l):
        if (x in 0..<w):
          yield g[y][z][x]

proc cost*(g: Grid, a, b: GNode): int = 1

proc heuristic*(g: Grid, next, goal: GNode): int = abs(goal.x - next.x) + abs(goal.y - next.y) + abs(goal.z - next.z)

when isMainModule:
  let g: Grid = newGrid()
  echo g

  let start: GNode = g[0][0][0]
  let goal: GNode = g[4][0][2]
  for n in g.neighbors(start):
    echo n, ", cost: ", g.cost(start, n), ", heuristic: ", g.heuristic(n, goal)

  
  for p in astar.path[Grid, GNode, int](g, start, goal):
    let gn: GNode = p
    echo gn

Error compiling example from README.md

nim   c --run  astar_tst.nim                                                                                                                   
Hint: used config file '/home/dvyal/tmp/nim-0.14.2/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: astar_tst [Processing]
Hint: astar [Processing]
Hint: binaryheap [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: etcpriv [Processing]
Hint: options [Processing]
Hint: typetraits [Processing]
astar_tst.nim(46, 18) Error: type mismatch: got (Grid) but expected 'Graph = astar'
% nim -v                                                                                                                                          
Nim Compiler Version 0.14.2 (2016-06-11) [Linux: amd64]
Copyright (c) 2006-2016 by Andreas Rumpf

git hash: abf4e204c2f1a8a6915a8d32c970b5ce64f58e10
active boot switches: -d:release

Push latest version to release

I want to use this package but I cannot get the latest version installed with nimble. If I do
nimble install astar
it will install the latest release which will not compile with recent versions of Nim. To make it work I have to manually download the files from github repository and work directly with the astar.nim file. Can the latest version of this package be released as a new version?

Exception in nim 1.2.2

Using astar in latest nim 1.2.2 is throwing an exception
... C:\Users\risharan\.nimble\pkgs\astar-0.4.0\astar.nim(25, 22) Error: undeclared identifier: 'THash'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.