Advertisement
Coriic

Untitled

Jun 4th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. hasWon:: Board->Color->Bool
  2. hasWon (Board map) color = Prelude.or (Prelude.map (\coords -> (checkAllDirections coords listOfCoordinates)) listOfCoordinates)
  3. where
  4. isFiveInDirection howMany (Coordinates x y) listOfCoordinates (xTranslation, yTranslation)
  5. | ((Coordinates x y) `elem` listOfCoordinates) = True && (isFiveInDirection (howMany+1) (Coordinates (x+xTranslation) (y+yTranslation)) listOfCoordinates (xTranslation, yTranslation))
  6. | ((Coordinates x y) `elem` listOfCoordinates) && howMany==5 = True
  7. | otherwise = False
  8. checkAllDirections coords listOfCoordinates = Prelude.any (isFiveInDirection 1 coords listOfCoordinates) [(x,y)| x<-[-1..1], y<-[-1..1], x/=0 && y/=0]
  9. listOfCoordinates = [coords | coords <- Map.keys map, fromJust (Map.lookup coords map) == color]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement