diff --git a/lib/PatienceBoard.hs b/lib/PatienceBoard.hs new file mode 100644 index 0000000..3253241 --- /dev/null +++ b/lib/PatienceBoard.hs @@ -0,0 +1,42 @@ +module PatienceBoard +( Board + +,initBoard +) where + +import CardDeck + +-- Representation of a Patience board +data Board = Board { + -- 7 colums of cards (the 'playing field') + gameStacks :: [Stack], + -- 4 ending stacks (top right corner, usually) + endingStacks :: [Stack], + -- Stack of cards that are not yet on the board + pile :: Stack +} deriving (Show) + +-- Show the first of a stack of cards. +showFirst :: Stack -> Stack +showFirst (c:cs) = (showCard c):cs + +-- Split a full deck into 7 gameStacks and one pile of unused cards. +splitDeck :: Stack -> [Stack] +splitDeck = reverse . splitDeck' 7 + where splitDeck' :: Int -> Stack -> [Stack] + splitDeck' 0 cs = [cs] + splitDeck' n cs = let (stack,rest) = splitAt n cs + in (showFirst stack):(splitDeck' (n - 1) rest) + +-- Return the initial board consisting of a stack of yet-to-be-turned +-- cards and 7 stacks of increasingly large amount of cards (1, ..., 7) +initBoard :: Board +initBoard = let pile:stacks = splitDeck generateShuffledDeck + in Board { + gameStacks = stacks, + endingStacks = [[],[],[],[]], + pile = pile + } + +moveBetweenStacks :: Stack -> Int -> Stack -> Stack +moveBetweenStacks from index to = undefined diff --git a/patience.cabal b/patience.cabal index 3b89f9e..214f1fa 100644 --- a/patience.cabal +++ b/patience.cabal @@ -7,7 +7,7 @@ build-type: Simple library hs-source-dirs: lib build-depends: base >= 4.7 && <5, random >= 1.1 && < 1.4 - exposed-modules: CardDeck, Shuffle + exposed-modules: CardDeck, PatienceBoard, Shuffle executable patience main-is: Main.hs