Question: Part 1 : Let's say you're a developer at a casual games company. You've been asked to write some starting code to be used for

Part 1:
Let's say you're a developer at a casual games company. You've been asked to write some starting code to be used for a card game. Your first assignment is to create a deck of cards and then create a function that can draw cards from the deck, one at a time.
//TODO:
//Create a new F# console application by using CLI: Cards
//Inside the Program.fs file,
//Create a list: cards representing deck with five cards in it: 1,2,3,4,5
//Design a function: drawCard for getting a card from deck each time.
Then you can use the code in the main() to test your solution:
[]
let main argv =
let result =
cards
|> drawCard
|> drawCard
|> drawCard
|> drawCard
printfn "%A" result
0
//Run your application, you will see the output:
1
2
3
4
[5]
Part 2:
The ability to draw cards from the deck is a great start, but card games ordinarily need two or more players to pick up those cards. As you know, each player's collection of drawn cards is called a hand. Next, you'll implement code to have each drawn card added to a hand.
// TODO:
// create an empty list: hand: each player's collection of drawn cards
// Next, modify the drawCard() method to accept a tuple that consists of two lists:
one representing the deck
and the other representing the hand:
// use fst() function to access the first property in the tuple (that is, your deck).
// use snd() function to access the hand.
// You also modified the return type so that it returns a tuple that consists of the deck and your hand (deck.Tail, hand),
// but with the added card firstCard.
Then you can use the code in the main() to test your solution:
[]
let main argv =
let d, h =
(cards,hand)
|> drawCards
|> drawCards
printfn "Deck: %A Hand: %A" d h
0
//Run your application, you will see the output:
Deck: [3; 4; 5] Hand: [2; 1]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!