Advertisement
Coriic

Untitled

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