Last active
November 3, 2015 00:14
-
-
Save punund/d0cb5d3275b92db2cd9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
leap ∷ Coor → Int2 → WithProblem Maybe Move | |
leap src dxy = do | |
let dst = src ~+ dxy | |
sqr ← squareAtM dst | |
kind ← captureM $ colorOnSquare sqr | |
return $ case kind of | |
SimpleMove -> [ Relocate src dst ] | |
CaptureMove -> [ Vacate dst, Relocate src dst ] | |
-- | linear movement by vector ij :: Int2 | |
ride ∷ Coor → Int2 → WithProblem Identity [Move] | |
ride src@(Coor xy) ij = unfoldrM rideAdvance (xy +% ij) | |
where | |
-- | unfoldrM wants m (Maybe (a, b)) | |
rideAdvance ∷ Int2 → WithProblem Identity (Maybe (Move, Int2)) | |
rideAdvance z = mapReaderT (Identity . makePair) (leap src (z -% xy)) | |
where | |
makePair ∷ Maybe Move → Maybe (Move, Int2) | |
makePair = liftM (, z +% ij) -- ^ tuple sections ahoy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment