-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpuzzle.nim
46 lines (36 loc) · 949 Bytes
/
npuzzle.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import src / [input_parser, parser, solver, types]
template helpMsg: string =
"""Usage: ./npuzzle -a:[a|g|u](-algorithm:type) -h:[m|h|lcm|e](-heuristic:type) file
Where:
Algorithms:
a: A-star
g: Greedy-best-first
u: Uniform-cost-search/Dijkstra
Heuristics:
m: Manhattan
h: Hemming
lcm: Linear conflicts + Manhattan
e: Euclidean
"""
template invalidMsg: string = "Invalid puzzle"
template unsolvableMsg: string = "Unsolvable puzzle"
proc main() =
try:
let clp = commandLineParams()
if clp.len == 0:
quit helpMsg(), QuitSuccess
let (ss, f) = parseInput[NPuzzleSettings] clp
let s = parseNPuzzle f
if not s.isValid:
quit invalidMsg()
let g = getGoal s
if not s.isSolvable(g):
quit unsolvableMsg()
var i: NPuzzleInfo
solve(s, g, ss, i)
i.show()
except Exception as e:
echo e.msg
when isMainModule:
main()