b0VIM 7.2 NՔOjulianalucenajuliana.local~julianalucena/cin/8-periodo/funcional/mancala/Board.hsutf-8 3210#"! UtpcadYckK1{z8 x U 2 1 m P 3 2  g ;   / . q F 4  xWxBS%~}XY-,+o6 w wh where halfBoardSize = (length (s1 ++ s2)) `div` 2 else player then getOtherPlayer playergetPlayerByPosition (player, pos) (s1, s2) = if pos >= halfBoardSizegetPlayerByPosition :: Hole -> Board -> Player boardSize = length (fst b ++ snd b) newPosition = ((pos + seeds) `mod` (boardSize - 1)) getPlayer = getPlayerByPosition (player, newPosition) b where seeds = (getPlayerHoles player b) !! posgetLastHole (player, pos) b = (getPlayer, newPosition `mod` (boardSize `div` 2))getLastHole :: Hole -> Board -> Hole otherPlayerHoles = (getOtherPlayerHoles player b) opositePos = length otherPlayerHoles - pos - 2 opositeSeeds = otherPlayerHoles !! opositePos holesRemovedSeeds = updateHole opositePos 0 (board2holes (getOtherPlayer player) b) mancalaPos = length holesRemovedSeeds - 1 newMancalaSeeds = (holesRemovedSeeds !! mancalaPos) + opositeSeeds where holesCapturedSeeds = updateHole mancalaPos newMancalaSeeds holesRemovedSeedscapture (player, pos) b = holes2board (getOtherPlayer player) holesCapturedSeedscapture :: Hole -> Board -> Board-- Captures other player's seeds seeds = (getPlayerHoles player b) !! pos allHoles = board2holes player b holesSeedsRemoved = updateHole pos 0 allHoles where sownBoard = sow seeds (pos + 1) holesSeedsRemovedmove (player, pos) b = holes2board player sownBoardmove :: Hole -> Board -> Board-- Makes the move toBeSown = take n (drop pos (removeMancalaHole holes)) where sown = map (+1) toBeSown (take pos holes ++ sown ++ drop (pos + length toBeSown) holes) else sow (n - length toBeSown) 0 then take pos holes ++ sown ++ drop (pos + n) holes if n <= length toBeSownsow n pos holes =sow :: Int -> Position -> [Seed] -> [Seed]-- Sows X seeds on holesupdateHole pos seed holes = take pos holes ++ (seed : drop (pos + 1) holes)updateHole :: Position -> Seed -> [Seed] -> [Seed]-- Updates seeds quantity on a hole else (snd (holes2board A holes), fst (holes2board A holes)) then splitAt (length holes `div` 2) holesholes2board p holes = if p == Aholes2board :: Player -> [Seed] -> Board else snd b ++ fst b then fst b ++ snd bboard2holes player b = if player == Aboard2holes :: Player -> Board -> [Seed]removeMancalaHole seeds = reverse (tail (reverse seeds))removeMancalaHole :: [Seed] -> [Seed]-- Return just normal holes else A then BgetOtherPlayer player = if player == AgetOtherPlayer :: Player -> PlayergetOtherPlayerHoles player b = getPlayerHoles (getOtherPlayer player) bgetOtherPlayerHoles :: Player -> Board -> [Seed]getPlayerHoles B board = snd boardgetPlayerHoles A board = fst boardgetPlayerHoles :: Player -> Board -> [Seed]-- Returns player's holes where holes = replicate nHoles seeds ++ [0]initBoard nHoles seeds = (holes, holes)initBoard :: Int -> Seed -> Board-- Inits Board with X holes (including mancala hole) with Y seedsimport Data.List(splitAt)import Types getLastHole) where capture, move, sow, updateHole, holes2board, board2holes, removeMancalaHole, getOtherPlayer, getOtherPlayerHoles, getPlayerHoles,module Board(initBoard,-- Mancala's board.-- Board.hs