Description
In this project, you are going to implement functions for Mini Card Game. It is a simple playing card game.
In Mini Card Game, there is only one player. The game is played with a card-list and a goal point. The player has a list of held-cards which is initially empty. The game is played with a list of moves which is provided at the beginning. The player can make 2 types of moves:
draw : With this move, the player takes the first card in the card-list and adds it to the held-cards. If the player draws a card c (it must be the first card in the card-list), the length of the card-list is reduced by one and the length of the held-cards is incremented by one.
discard: With this move, the player removes any one card from the held-cards. If the player discards a card c, the game continues with the held-cards except c. The card-list is unchanged. The discard card selection strategy is not specified. You can implement your own strategy.
The objective of Mini Card Game is to end the game with a low score.
Scoring details : Let playerpoint be the sum of the values of held-cards, goal be the goal point which is an integer value. First of all, prescore for the player is calculated. The finalscore is calculated with prescore according to held-cards. The prescore is 5 times ( playerpoint – goal ), if the playerpoint is greater than goal. Otherwise, the prescore is ( goal – playerpoint ). The finalscore is the prescore, if there are different colored cards in held-cards list. If all the held-cards are same color, the finalscore is the half of the prescore (rounded down with integer division).
The game has 4 endings:
Game-Over-1: If the list of moves is empty, the game ends.
Game-Over-2: If the current move is draw and the card-list is empty, the game ends.
Game-Over-3: If the current move is discard and the held-cards is empty, the game ends.
Game-Over-4: At any time if the sum of the values in the held-cards is greater than the goal after the last move, the game ends.
3Â Â Â Â Â Â Â Â An Example Play
Game elements are:
- card-list: It is the deck of cards on the table.
- move-list: It is the list of moves for the player. It is given at the beginning of the game.
- goal: It is the minimum score that the player wants to approach.
- held-cards: It is the list of cards that the player is holding. It is an empty list at the beginning of the game.
Lets play an example game to warm up. Our inputs are:
- card-list: ’((H . 3) (H . 2) (H . A) (D . A) (D . Q) (D . J))
- move-list: ’(draw draw draw discard)
- goal: 20
- held-cards: ’()
’(H . 3) is three of Hearts and ’(D . J) is Jack of Diamonds.
Move 1: draw – Take the first card from card-list and append to held-cards. After this move:
- card-list: ’((H . 2) (H . A) (D . A) (D . Q) (D . J))
- move-list: ’(draw draw discard)
- goal: 20
- held-cards: ’((H . 3))
Move 2: check – The sum of held-cards is 3 and is less than the goal (20). So continue.
Move 3: draw – Take the first card from card-list and append to held-cards. After this move:
- card-list: ’((H . A) (D . A) (D . Q) (D . J))
- move-list: ’(draw discard)
- goal: 20
- held-cards: ’((H . 3) (H . 2))
Move 4: check – The sum of held-cards is 5 and is less than the goal (20). So continue.
Move 5: draw – Take the first card from card-list and append to held-cards. After this move:
- card-list: ’((D . A) (D . Q) (D . J))
- move-list: ’(discard)
- goal: 20
- held-cards: ’((H . 3) (H . 2) (H . A))
Move 6: check – The sum of held-cards is 16 and is less than the goal (20). So continue.
Move 7: discard – Choose one card from held-cards and put it away. For this example lets choose the first card to remove. After this move:
- card-list: ’((D . A) (D . Q) (D . J))
- move-list: ’()
- goal: 20
- held-cards: ’((H . 2) (H . A))
Move 8: check – The sum of held-cards is 13 and is less than the goal (20). So continue. Move 9: check – The list of moves is empty. So game ends.
Lets calculate our score.
The playerpoint is the sum of held-cards, that is 13 at the end of the game.
The playerpoint is less than the goal, so the prescore is (goal – playerpoint), that is 7.
We have all Hearts in held-cards, therefore all the cards are same color.
The finalscore is half of the prescore because all cards are same color, that is 3 as rounded down.
At the end, our finalscore is 3. Congratulations!
4Â Â Â Â Â Â Â Â The Functions
You should implement the following functions for Mini Card Game:
4.1Â Â Â ) (card-color one-card)
Returns the color of one-card.
Hint: Hearts (H) and Diamonds (D) are red. Spades (S) and Clubs (C) are black.
> ( card-color ‘(H . A) )
‘red
> ( card-color ‘(S . 10) )
‘black
4.2Â Â Â () (card-rank one-card)
Returns the rank of one-card.
Hint: Use 11 for ace (A), 10 for king (K) and queen (Q) and jack (J), and numbers
> ( card-rank ‘(H . A) )
11
> ( card-rank ‘(S . 10) )
10
4.3Â Â Â () (all-same-color list-of-cards)
Returns #t if all the cards in list-of-cards have same color, #f otherwise.
> ( all-same-color ‘((H . 3) (H . 2) (H . A) (D . A) (D . Q) (D . J)) )
#t
> ( all-same-color ‘((S . 3) (S . 2) (S . A) (C . A) (C . Q) (C . J)) )
#t
> ( all-same-color ‘((H . 3) (H . 2) (H . A) (D . A) (D . Q) (C . J)) ) #f
4.4Â Â Â () (fdraw list-of-cards held-cards)
Returns a new list of held-cards after the action draw is taken.
> ( fdraw ‘((H . 3) (H . 2) (H . A) (D . A) (D . Q) (D . J)) ‘())
‘((H . 3))
> ( fdraw ‘((H . 3) (H . 2) (H . A) (D . A) (D . Q) (D . J)) ‘((S . 3) (S . 2) (S . A))) ‘((S . 3) (S . 2) (S . A) (H . 3))
4.5Â Â Â ) (fdiscard list-of-cards list-of-moves goal held-cards)
Returns a new list of held-cards after the action discard is taken.
Hint: list-of-cards and list-of-moves and goal are also provided as arguments so that you can generate a better gaming strategy than your friends to reach a lower score.
| > ( fdiscard ‘((C . 3) (C . 2) (C . A) (S . J) (S . Q) (H . J))
‘(draw draw draw discard) 66 ‘((H . 3) (H . 2) (H . A) (D . A) (D . Q) (D . J)) ‘((H . 3) (H . 2) (H . A) (D . A) (D . Q))   ;output > ( fdiscard ‘((H . 3) (H . 2) (H . A) (D . A) (D . Q) (D . J)) ‘(draw draw draw discard) 56 ‘((S . 3) (S . 2) (S . A) (C . A) (C . Q) (C . J)) ) ‘((S . 3) (S . 2) (C . A) (C . Q) (C . J))   ;output |
) |
4.6Â Â Â ) (find-steps list-of-cards list-of-moves goal)
Returns a list of steps that is a list of pairs of moves and corresponding cards along the game.
Note: Remember and be careful about Game-Over-4!
| > ( find-steps ‘((H . 3) (H . 2) (H . A) (D . J) (D . Q) (C . J)) ‘(draw draw draw discard
‘((draw (H . 3)) (draw (H . 2)) (draw (H . A)) (discard (H . 3))) |
) 16 )
4.7Â Â Â () (find-held-cards list-of-steps)
Returns the list of held-cards after the list-of-steps is applied. Remember the list of held-cards is initially empty.
> ( find-held-cards ‘((draw (H . 3)) (draw (H . 2)) (draw (H . A)) (discard (H . 3))) )
‘((H . 2) (H . A))
4.8Â Â Â () (calc-playerpoint list-of-cards)
Calculates and returns the corresponding playerpoint for list-of-cards. The calculation is described in definition part.
Hint: Use 11 for ace, 10 for king and queen and jack, and numbers
> ( calc-playerpoint ‘((H . A) (H . 3) (H . 2) (D . Q) (D . J) (C . J)) )
46
4.9Â Â Â () (calc-score list-of-cards goal)
Calculates and returns finalscore according to the definition part using inputs list-of-cards and goal.
> ( calc-score ‘((H . 3) (H . 2) (H . A) (D . J) (D . Q) (C . J)) 50 )
4
> ( calc-score ‘((H . 3) (H . 2) (H . A) (D . J) (D . Q) (C . J)) 16 )
150
4.10 () (play list-of-cards list-of-moves goal)
Returns finalscore at the end of the game after processing (some or all of) the moves in the move list in order.
| > ( play ‘((H . 3) (H . 2) (H . A) (D . J) (D . Q) (C . J)) ‘(draw draw draw discard
1 (Note: (H . 3) is discarded for discard move.) |
) 16 )
5Â Â Â Â Â Â Â Â BONUS ()
We are going to test your play functions in a competition. You will be able to receive bonus points according to your rank in the competition. Remember lowest score wins!




