1
Fork 0

Added basic PatienceBoard

This commit is contained in:
Tibo De Peuter 2022-11-08 10:30:31 +01:00
parent 9ca1cdd534
commit 13ee95c6ec
2 changed files with 43 additions and 1 deletions

42
lib/PatienceBoard.hs Normal file
View file

@ -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

View file

@ -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