Skip to content
Snippets Groups Projects
Commit 89a62282 authored by ik1g19's avatar ik1g19
Browse files

removed findPlacement repetition

parent 1166ca9a
No related branches found
No related tags found
No related merge requests found
...@@ -66,21 +66,19 @@ findLocation css (x,y) s@(l:ls) | x > limit && y > limit = N ...@@ -66,21 +66,19 @@ findLocation css (x,y) s@(l:ls) | x > limit && y > limit = N
{--| checks for hidden word in possible directions |--} {--| checks for hidden word in possible directions |--}
findPlacement :: WordSearchGrid -> Posn -> String -> Maybe Placement findPlacement :: WordSearchGrid -> Posn -> String -> Maybe Placement
findPlacement css (x,y) s | checkWordDir css (x,y) Forward s = Just ((x,y),Forward) findPlacement css (x,y) s = findP dirs
| checkWordDir css (x,y) Back s = Just ((x,y),Back) where
| checkWordDir css (x,y) Up s = Just ((x,y),Up) findP [] = Nothing
| checkWordDir css (x,y) Down s = Just ((x,y),Down) findP (d:ds) | checkWordDir css (x,y) s d = Just ( (x,y),d )
| checkWordDir css (x,y) UpForward s = Just ((x,y),UpForward) | otherwise = findP ds
| checkWordDir css (x,y) UpBack s = Just ((x,y),UpBack)
| checkWordDir css (x,y) DownForward s = Just ((x,y),DownForward) dirs = [Forward,Back,Up,Down,UpForward,UpBack,DownForward,DownBack]
| checkWordDir css (x,y) DownBack s = Just ((x,y),DownBack)
| otherwise = Nothing
checkWordDir :: WordSearchGrid -> Posn -> String -> Orientation -> Bool
checkWordDir css (x,y) (l:[]) dir | nextElem css (x,y) dir == Just l = True
checkWordDir :: WordSearchGrid -> Posn -> Orientation -> String -> Bool
checkWordDir css (x,y) dir (l:[]) | nextElem css (x,y) dir == Just l = True
| otherwise = False | otherwise = False
checkWordDir css (x,y) dir (l:ls) | nextElem css (x,y) dir == Just l = checkWordDir css (nextPos dir (x,y)) dir ls checkWordDir css (x,y) (l:ls) dir | nextElem css (x,y) dir == Just l = checkWordDir css (nextPos dir (x,y)) ls dir
| otherwise = False | otherwise = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment