-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
27 lines (24 loc) · 960 Bytes
/
Main.hs
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
import System.Environment
import Data.List
--import Data.Maybe
import AStar
import Parser
import NPuzzle
import Heuristics
main :: IO ()
main = do args <- getArgs
if length args /= 1
then putStrLn "Usage: ./graphi file/path"
else do
content <- readFile (head args)
case parseGrid (head args) content of
Left err -> print err
Right grid -> do putStr content
putStrLn "--solution--"
let goal = generateGoal $ intRoot $ length grid
let path = aStarSearch expand cost (manhattan goal) (== goal) (toArray grid)
putStr $ maybe "No path available\n" showPath path
showPath :: [Grid] -> String
showPath = foldl' (\str state -> str ++ showGrid state ++ "\n") ""
intRoot :: Int -> Int
intRoot = truncate . sqrt . (fromIntegral :: Int -> Double)