Reputation: 674
I want to implement a simple 8off solitaire game in haskell and I am not quite sure how to define my board, and how to make a function to return a random starting board. How can I modify myBoard and my data structure? Until now, I have these:
data Pip = A|TW0|THREE|FOUR|FIVE|SIX|SEVEN|EIGHT|NINE|TEN|J|Q|K --pip value
deriving (Eq,Show)
data Suit = S|H|D|C --suit
deriving (Eq,Show)
type Card = (Pip,Suit) --card
type Deck = [(Card)] --deck
type Foundations = [(Deck)] foundations
type Columns = [(Deck)] --columns
type Reserve = [(Deck)] --reserve
type EOBoard = [(Deck)]
myBoard::Deck->EOBoard
myBoard pack = [shuffle pack]
which returns me, this:
[[(K,D),(TW0,H),(SEVEN,C),(SEVEN,S),(THREE,D),(NINE,S),(THREE,C),(FOUR,H),(THREE,S),(TW0,D),(TW0,C),(FOUR,S),(K,S),(TEN,D),(J,S),(EIGHT,H),(FOUR,D),(NINE,H),(SEVEN,H),(A,S),(SIX,S),(EIGHT,S),(FIVE,S),(FOUR,C),(K,H),(Q,D),(THREE,H),(TEN,H),(A,D),(EIGHT,C),(NINE,D),(Q,H),(J,D),(J,C),(TEN,C),(Q,S),(Q,C),(J,H),(NINE,C),(SIX,C),(FIVE,H),(SEVEN,D),(A,C),(TW0,S),(EIGHT,D),(FIVE,D),(TEN,S),(K,C),(A,H),(SIX,D),(FIVE,C),(SIX,H)]]
Upvotes: 1
Views: 1437
Reputation: 625
Looks like you're off to a good start! Perhaps you're ready to put some of these components together to form your board.
You might consider making a Board/Game ADT.
You might then like to have a default function, which sets up the default state of your Board.
defaultFoundation
which returns a Foundation
containing four empty Deck
sdefaultColumns
which takes a Deck
and splits it, returning a Columns
containing 8 Deck
s with 6 cards each (maybe you want to only pass in the first 48 cards from the Deck only).defaultReserves
which returns a Reserve
with 8 Deck
s, 4 with cards and 4 empty (maybe here is where you want to pass in those remaining 4 cards from the Deck
)You're doing fine so far, take it one step at a time. :)
Upvotes: 4