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
- listOfCoordinates = [coords | coords <- Map.keys map, fromJust (Map.lookup coords map) == color]
- checkAllDirections:: [Coordinates]->Coordinates->Bool
- checkAllDirections listOfCoordinates coords = Prelude.any (isFiveInDirection 1 coords listOfCoordinates) [(x,y)| x<-[-1..1], y<-[-1..1], x/=0 && y/=0]
- isFiveInDirection:: Int->Coordinates->[Coordinates]->(Int,Int)->Bool
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement