Skip to content

Instantly share code, notes, and snippets.

@punund
Last active November 3, 2015 00:14
Show Gist options
  • Save punund/d0cb5d3275b92db2cd9e to your computer and use it in GitHub Desktop.
Save punund/d0cb5d3275b92db2cd9e to your computer and use it in GitHub Desktop.
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