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
{--| checks for hidden word in possible directions |--}
findPlacement :: WordSearchGrid -> Posn -> String -> Maybe Placement
findPlacement css (x,y) s | checkWordDir css (x,y) Forward s = Just ((x,y),Forward)
| checkWordDir css (x,y) Back s = Just ((x,y),Back)
| checkWordDir css (x,y) Up s = Just ((x,y),Up)
| checkWordDir css (x,y) Down s = Just ((x,y),Down)
| checkWordDir css (x,y) UpForward s = Just ((x,y),UpForward)
| checkWordDir css (x,y) UpBack s = Just ((x,y),UpBack)
| checkWordDir css (x,y) DownForward s = Just ((x,y),DownForward)
| checkWordDir css (x,y) DownBack s = Just ((x,y),DownBack)
| otherwise = Nothing
checkWordDir :: WordSearchGrid -> Posn -> Orientation -> String -> Bool
checkWordDir css (x,y) dir (l:[]) | nextElem css (x,y) dir == Just l = True
findPlacement css (x,y) s = findP dirs
where
findP [] = Nothing
findP (d:ds) | checkWordDir css (x,y) s d = Just ( (x,y),d )
| otherwise = findP ds
dirs = [Forward,Back,Up,Down,UpForward,UpBack,DownForward,DownBack]
checkWordDir :: WordSearchGrid -> Posn -> String -> Orientation -> Bool
checkWordDir css (x,y) (l:[]) dir | nextElem css (x,y) dir == Just l = True
| 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment