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