topkata 0.2.2 → 0.2.3
raw patch · 2 files changed
+40/−2 lines, 2 files
Files
- Dijkstra.hs +38/−0
- topkata.cabal +2/−2
+ Dijkstra.hs view
@@ -0,0 +1,38 @@+module Dijkstra + (dijkstra)+where++import Data.Ix+import Data.Array+import Data.Maybe+import Data.List++{-+class RasterWorld rw where+ neighbors :: Ix a => rw -> a -> [a]+ rwbounds :: Ix a => rw -> (a, a)+-} ++-- dijkstra :: (Ix a, RasterWorld rw) => rw -> a -> Array a Int+dijkstra rw pos bnds neighbors =+ dijkstraUpdate rw (initArray // [(pos, 0)]) (neighbors rw pos) neighbors+ where + rng = range bnds+ initArray = array bnds [ (ix, maxBound :: Int) | ix <- rng ]++-- dijkstraUpdate :: (Ix a, RasterWorld rw) => rw -> Array a Int -> [a] -> Array a Int+dijkstraUpdate rw a todo neighbors = + if null todo' then a' else dijkstraUpdate rw a' (nub todo') neighbors+ where + (update, todo') = foldl updateOne ([], []) todo+ a' = a // update+ updateOne acc@(u, td) ix =+ let nbDist = 1+(minimum $ map (a !) nb)+ nb = neighbors rw ix+ in+ if nbDist < a ! ix then ((ix, nbDist):u, nb ++ td)+ else acc++ + +
topkata.cabal view
@@ -1,5 +1,5 @@ Name: topkata-Version: 0.2.2+Version: 0.2.3 Synopsis: OpenGL Arcade Game Description: Guide a jumping ball through a maze. License: GPL@@ -37,7 +37,7 @@ Build-Depends: base, filepath, GLUT, OpenGL, array, random Other-Modules: Labygen, Labygen.Render, Topkata.Topka.Topka, Topkata.Topka.Ghost, Topkata.Topka.Base- Vector, ReadImage+ Vector, ReadImage, Dijkstra Extensions: CPP if flag(sound) Build-Depends: OpenAL, ALUT