it wont even compile
nymph.nim(26, 16) Error: type mismatch: got (Map) but expected 'Graph = astar'
i was going to leave it running on a vps
I got it working after a bit of back-and-forth. I had to upgrade to the latest version of astar (with nimble install 'astar@#head'), and move the 'Bot' concept to an object that StatelessBot inherited from (and moved the decide proc into a closure). Couldn't keep as top-level, since closure calling convention not allowed for top-level procs.
let nymph = StatelessBot(
name: "Nymph",
key: readFile("nymph.key"),
decide: (proc(m: Map): Dir {.closure, locks:0.}=
let me = m.hero
let tgt = find_nearest[Hero](m, me.pos, m.heroes, proc(h:Hero): bool = me.id != h.id )
let path = astar_path(m, m.hero.pos, tgt.pos)
let d = getDir(m.hero.pos, path[0])
echo format("Chasing $1; Moving $2", tgt.id, d)
result = d
proc printer(pos:Pos, t:Tile): string =
result = printTile(t)
if t == tEmpty:
for i,p in path:
if p == pos:
result = $(i+1)
break
Print(m.grid,printer)
)
)
In debugging, I found that nim c --reportConceptFailures:on gets squirrelly when you have something that uses 'when compiles(foo)' and foo doesn't compile, but I need to see if I can get a clean way of reproducing that before submitting an issue. There might be a way to keep Bot as a concept, but I'd have to play with it more.
Got working as concepts :) : Just had to change the concept definition to use a variable rather than typedef for Map
type Bot* = concept b
var m: Map
decide(b, m) is Dir
b.name is string
b.key is string
type StatelessBot* = object
name*: string
key*: string
and change the nymph_bot proc for StatelessBot to globally-available 'decide' proc:
# In nymph.nim
# proc nymph_bot(b:StatelessBot, m:Map):Dir =
proc decide*(b: StatelessBot, m: Map): Dir =
it wont even compile
oh, sorry. Looks like I tested it using a modified compiler. I reverted patch https://github.com/nim-lang/Nim/commit/e04f3195407cc99f958dd81e0a9d58fe5414e631 which apparently breaks some concept-related functionality. See https://github.com/nim-lang/Nim/issues/4084
@perturbation2 Can you please elaborate a bit more? I bootstrapped the devel branch of Nim compiler, applied your changes(as I understood them) and got the same error as @UnnoTed. This is the code: https://github.com/akamaus/vindinium-nim-starter-kit/tree/buggy
I created a branch with my changes and did a PR: https://github.com/akamaus/vindinium-nim-starter-kit/pull/1
Feel free to ignore or close that (accidentally made it against your master branch rather than the 'buggy' branch). I just wanted to do that to better explain what my changes were. I'm still running the HEAD version of astar with nimble install 'astar@#HEAD', with latest compiler from devel branch.