42 lines
1.3 KiB
Haskell
42 lines
1.3 KiB
Haskell
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
|