moveHorizontal :: Board -> Edge -> Int -> (Board, Bool)
moveHorizontal b e@((p1,p2),(q1,q2)) p
  | p1 == 0        = (y1 ++ tail b, y2)
  | p1 == length b = (init b ++ x1, x2)
  | otherwise      = (take (p1-1) b ++ x1 ++ y1 ++ drop (p1+1) b, x2 || y2)
    where x  = fst $ (b !! (p1-1)) !! p2
          x1 = [take p2 (b !! (p1-1)) ++ [(e:x, if x2 then p else 0)] ++ drop (p2+1) (b !! (p1-1))]
          x2 = length x == 3
          y  = fst $ (b !! p1) !! p2
          y1 = [take p2 (b !! p1) ++ [(e:y, if y2 then p else 0)] ++ drop (p2+1) (b !! p1)]
          y2 = length y == 3
moveHorizontal :: Board -> Edge -> Int -> (Board, Bool)
moveHorizontal b e@((p1,p2),(q1,q2)) p
  | p1 == 0        = (y1 ++ tail b, y2)
  | p1 == length b = (init b ++ x1, x2)
  | otherwise      = (take (p1-1) b ++ x1 ++ y1 ++ drop (p1+1) b, x2 || y2)
    where x  = fst $ (b !! (p1-1)) !! p2
          x1 = [take p2 (b !! (p1-1)) ++ [(e:x, if x2 then p else 0)] ++ drop (p2+1) (b !! (p1-1))]
          x2 = length x == 3
          y  = fst $ (b !! p1) !! p2
          y1 = [take p2 (b !! p1) ++ [(e:y, if y2 then p else 0)] ++ drop (p2+1) (b !! p1)]
          y2 = length y == 3
moveHorizontal b e@((p1,p2),(q1,q2)) p
  | p1 == 0        = (y1 ++ tail b, y2)
  | p1 == length b = (init b ++ x1, x2)
  | otherwise      = (take (p1-1) b ++ x1 ++ y1 ++ drop (p1+1) b, x2 || y2)
    where x  = fst $ (b !! (p1-1)) !! p2
          x1 = [take p2 (b !! (p1-1)) ++ [(e:x, if x2 then p else 0)] ++ drop (p2+1) (b !! (p1-1))]
          x2 = length x == 3
          y  = fst $ (b !! p1) !! p2
          y1 = [take p2 (b !! p1) ++ [(e:y, if y2 then p else 0)] ++ drop (p2+1) (b !! p1)]
          y2 = length y == 3