moveVertical :: Board -> Edge -> Int -> (Board, Bool)
moveVertical b e@((p1,p2),(q1,q2)) p
  | p2 == 0               = (take (max 0 p1) b ++ [a1] ++ drop (min (length (head b)) (p1+1)) b, y1)
  | p2 == length (head b) = (take (max 0 p1) b ++ [a2] ++ drop (min (length (head b)) (p1+1)) b, x1)
  | otherwise             = (take (max 0 p1) b ++ [a3] ++ drop (min (length (head b)) (p1+1)) b, x1 || y1)
    where x  = fst $ (b !! p1) !! (p2-1)
          x1 = length x == 3
          y  = fst $ (b !! p1) !! p2
          y1 = length y == 3
          z  = b !! p1
          a1 = (e:y, if y1 then p else 0) : tail z
          a2 = init z ++ [(e:x, if x1 then p else 0)]
          a3 = take (p2-1) z ++ [(e:x, if x1 then p else 0)] ++ [(e:y, if y1 then p else 0)] ++ drop (p2+1) z


-- BOARD CHECKS
moveVertical :: Board -> Edge -> Int -> (Board, Bool)
moveVertical b e@((p1,p2),(q1,q2)) p
  | p2 == 0               = (take (max 0 p1) b ++ [a1] ++ drop (min (length (head b)) (p1+1)) b, y1)
  | p2 == length (head b) = (take (max 0 p1) b ++ [a2] ++ drop (min (length (head b)) (p1+1)) b, x1)
  | otherwise             = (take (max 0 p1) b ++ [a3] ++ drop (min (length (head b)) (p1+1)) b, x1 || y1)
    where x  = fst $ (b !! p1) !! (p2-1)
          x1 = length x == 3
          y  = fst $ (b !! p1) !! p2
          y1 = length y == 3
          z  = b !! p1
          a1 = (e:y, if y1 then p else 0) : tail z
          a2 = init z ++ [(e:x, if x1 then p else 0)]
          a3 = take (p2-1) z ++ [(e:x, if x1 then p else 0)] ++ [(e:y, if y1 then p else 0)] ++ drop (p2+1) z


-- BOARD CHECKS
moveVertical b e@((p1,p2),(q1,q2)) p
  | p2 == 0               = (take (max 0 p1) b ++ [a1] ++ drop (min (length (head b)) (p1+1)) b, y1)
  | p2 == length (head b) = (take (max 0 p1) b ++ [a2] ++ drop (min (length (head b)) (p1+1)) b, x1)
  | otherwise             = (take (max 0 p1) b ++ [a3] ++ drop (min (length (head b)) (p1+1)) b, x1 || y1)
    where x  = fst $ (b !! p1) !! (p2-1)
          x1 = length x == 3
          y  = fst $ (b !! p1) !! p2
          y1 = length y == 3
          z  = b !! p1
          a1 = (e:y, if y1 then p else 0) : tail z
          a2 = init z ++ [(e:x, if x1 then p else 0)]
          a3 = take (p2-1) z ++ [(e:x, if x1 then p else 0)] ++ [(e:y, if y1 then p else 0)] ++ drop (p2+1) z


-- BOARD CHECKS