------------------------------------------------------------------------------
-- | if the move is legal then Just move and the new Legality
legalCheck :: Legality -> PseudoLegalMove -> (Legality, Maybe Move)
legalCheck l psm@(PseudoLegalMove m) =
  if psm `S.member` (l^.nubs)
  then (l, Nothing)
  else
    let f  = if l^.inCheck'
             then legal (l^.board)
             else ok (l^.board) (l^.pins)
        nl = (nubs %~ S.insert psm) l
    in (nl, if f m then Just m else Nothing)
legalCheck :: Legality -> PseudoLegalMove -> (Legality, Maybe Move)
legalCheck l psm@(PseudoLegalMove m) =
  if psm `S.member` (l^.nubs)
  then (l, Nothing)
  else
    let f  = if l^.inCheck'
             then legal (l^.board)
             else ok (l^.board) (l^.pins)
        nl = (nubs %~ S.insert psm) l
    in (nl, if f m then Just m else Nothing)
legalCheck l psm@(PseudoLegalMove m) =
  if psm `S.member` (l^.nubs)
  then (l, Nothing)
  else
    let f  = if l^.inCheck'
             then legal (l^.board)
             else ok (l^.board) (l^.pins)
        nl = (nubs %~ S.insert psm) l
    in (nl, if f m then Just m else Nothing)