Difference between revisions of "Hearts Card Game Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
(Created page with "[https://www.cse.wustl.edu/~cosgroved/courses/cse425s/spring20/studio_hearts.pdf Instructions]")
 
Line 1: Line 1:
 
[https://www.cse.wustl.edu/~cosgroved/courses/cse425s/spring20/studio_hearts.pdf Instructions]
 
[https://www.cse.wustl.edu/~cosgroved/courses/cse425s/spring20/studio_hearts.pdf Instructions]
 +
 +
Given these type definitions:
 +
 +
<nowiki>datatype suit = Clubs | Diamonds | Hearts | Spades
 +
datatype rank = Jack | Queen | King | Ace | Num of int
 +
type card = suit * rank
 +
type player = card list</nowiki>
 +
 +
==cards==
 +
===is_card_valid===
 +
Define a function is_card_valid which accepts a card parameter.
 +
is_card_valid should evaluate to false if the int value of the Num constructor is
 +
less than 2 or greater than 10. Otherwise, it should evaluate to true
 +
 +
===are_all_cards_valid===
 +
Define a function are_all_cards_valid which accepts a card list parameter.
 +
are_all_cards_valid should evaluate to false if any of the cards in the list are
 +
invalid, and true otherwise. Note: the empty list is valid.
 +
 +
are_all_cards_valid may be tail-recursive or not at your preference.
 +
 +
==hearts==
 +
From here on you will no longer need to concern yourself with invalid cards.
 +
 +
Hearts is an trick-taking card game. Further, Hearts is an "evasion-type" card game
 +
where the objective is to avoid taking positive penalty point cards. The Queen of
 +
Spades as well as each and every Heart are positive penalty point cards. Therefore,
 +
players attempt to avoid taking those cards. The Jack of Diamonds is the one favorable card players strive to take (it is worth negative penalty points). For simplicity,
 +
we will ignore a common variation which involves a player "shooting the moon" by
 +
taking all of the positive penalty point cards.
 +
 +
For the remainder of this assignment you will write code to calculate scores, count
 +
the number of cards, as well as detect possible shenanigans of a player/players not
 +
turning in all of their penalty point cards.
 +
 +
Note: "shenanigans" are devious tricks used especially for an underhand purpose.
 +
 +
===card_score===
 +
Define a function card_score which accepts a card parameter.
 +
card_score should evaluate to the int point value of the card as specified below:
 +
 +
The Queen of Spades: 13 points
 +
Each Heart: 1 point
 +
The Jack of Diamonds: minus 10 points
 +
All other cards: 0 points
 +
 +
Recall: ~ is the unary minus operator in SML.

Revision as of 04:55, 5 October 2020

Instructions

Given these type definitions:

datatype suit = Clubs | Diamonds | Hearts | Spades
datatype rank = Jack | Queen | King | Ace | Num of int 
type card = suit * rank
type player = card list

cards

is_card_valid

Define a function is_card_valid which accepts a card parameter. is_card_valid should evaluate to false if the int value of the Num constructor is less than 2 or greater than 10. Otherwise, it should evaluate to true

are_all_cards_valid

Define a function are_all_cards_valid which accepts a card list parameter. are_all_cards_valid should evaluate to false if any of the cards in the list are invalid, and true otherwise. Note: the empty list is valid.

are_all_cards_valid may be tail-recursive or not at your preference.

hearts

From here on you will no longer need to concern yourself with invalid cards.

Hearts is an trick-taking card game. Further, Hearts is an "evasion-type" card game where the objective is to avoid taking positive penalty point cards. The Queen of Spades as well as each and every Heart are positive penalty point cards. Therefore, players attempt to avoid taking those cards. The Jack of Diamonds is the one favorable card players strive to take (it is worth negative penalty points). For simplicity, we will ignore a common variation which involves a player "shooting the moon" by taking all of the positive penalty point cards.

For the remainder of this assignment you will write code to calculate scores, count the number of cards, as well as detect possible shenanigans of a player/players not turning in all of their penalty point cards.

Note: "shenanigans" are devious tricks used especially for an underhand purpose.

card_score

Define a function card_score which accepts a card parameter. card_score should evaluate to the int point value of the card as specified below:

The Queen of Spades: 13 points Each Heart: 1 point The Jack of Diamonds: minus 10 points All other cards: 0 points

Recall: ~ is the unary minus operator in SML.