A* search algorithm: Difference between revisions

Content added Content deleted
(Change in the way to write the path in "printSolution".)
Line 1,832: Line 1,832:
proc printSolution(path: seq[Cell]; cost: int) =
proc printSolution(path: seq[Cell]; cost: int) =
## Print the solution.
## Print the solution.
var pathLine = "Path: "
stdout.write(&"Path: ({path[0].row}, {path[0].col})")
let start = pathLine.len
for idx in 1..path.high:
let cell = path[idx]
for cell in path:
stdout.write(&" → ({cell.row}, {cell.col})")
pathLine.addSep(" → ", start)
stdout.write(&"\nCost: {cost}\n")
pathLine.add(&"({cell.row}, {cell.col})")
echo '\n'
echo pathLine
echo(&"Cost: {cost}\n\n")
drawBoard(path)
drawBoard(path)