From 8cb868224840c734f38e9041aa1567cdecd17797 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 2 Apr 2013 01:22:31 -0400 Subject: Cleaned up FunMap --- Fallen/FunMap.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Fallen/FunMap.hs') diff --git a/Fallen/FunMap.hs b/Fallen/FunMap.hs index 809bd4c..07d4a77 100644 --- a/Fallen/FunMap.hs +++ b/Fallen/FunMap.hs @@ -24,25 +24,25 @@ module Fallen.FunMap } -- emptyMap :: Int -> Int -> Tile -> Map - emptyMap w h t = Map { dimension=(w,h), mapdata=(\p -> t), background=t } + emptyMap w h t = Map { dimension=(w,h), mapdata= const t, background=t } -- inBounds :: Map -> Point -> Bool inBounds m (x,y) = let (w,h) = dimension m in (x >= 0) && (x < w) && (y >= 0) && (y < h) -- getTileAtPos :: Map -> Point -> Tile - getTileAtPos m p = if (inBounds m p) + getTileAtPos m p = if inBounds m p then mapdata m p else background m -- findTileInMap :: Map -> Tile -> [Point] -- REALLY inefficient - findTileInMap m t = filter (\p -> t == mapdata m p) rawPoints where + findTileInMap m t = filter (==t) $ map (mapdata m) rawPoints where (w,h) = dimension m rawPoints = [(x,y) | x <- [0..w-1], y <- [0..h-1]] -- updateMap :: Point -> Tile -> Map -> Map updateMap p t (Map d xs bg) = Map d (redirect p t xs) bg where - redirect p t xs = (\p2 -> if p == p2 then t else xs p2) + redirect p t xs p2 = if p == p2 then t else xs p2 -- legalMoves :: Map -> Point -> [Tile] -> [Direction] legalMoves m p ts = map fst $ filter legal $ map tileDir directions where @@ -51,6 +51,6 @@ module Fallen.FunMap -- fillMapRect :: Int -> Int -> Int -> Int -> Tile -> Map -> Map fillMapRect x y w h t (Map d xs bg) = Map d redirectInBounds bg where - redirectInBounds = (\p -> if (inBounds p) then t else xs p) + redirectInBounds p = if inBounds p then t else xs p inBounds (px,py) = (px >= x) && (px < (x+w)) && (py >= y) && (py < (y+h)) \ No newline at end of file -- cgit 1.4.1