Play a hand of bridge.
The object of this assignment is to play legally, that is, according to the rules of bridge. Playing well, and attempting to win the game, is outside the scope of this assignment.
There are four players. Each player gets 13 cards. A suit and a player are chosen (randomly). The chosen player plays the first card, and each of the other players then plays a card (of the same suit, if possible). The player who played the highest card wins the "trick" (the four cards just played) and plays the first card of the next trick.
The assignment: Shuffle and deal the cards, then play the hand (13 tricks). Follow the rules for what cards may be played, but don't try to implement any strategy or any scoring.
Cards and the card deck are as described in the previous assignment. In fact, the
Card class (as given in Bid.scala) can be used without any changes.
There are four players, whom we will call
Here's how it goes:
dealmethod in Bid.scala is inadequate for dealing more than one hand.)
"No Trump". "No trump" means just what it sounds like: No suit is trump. This suit will remain trump until the entire hand has been played.
Next, thirteen tricks are played. Each trick proceeds as follows:
After doing the above 13 times, all cards have been played and the hand ends.
There is no strategy to this game, it isn't scored, nobody wins or loses.
After the cards are shuffled and dealt:
||If the trump suit is anything but Diamonds, East wins the trick.|
|If the trump suit is Diamonds, South wins the trick.|
Your program should detrmine who won the trick, but it does not have to keep track of all the tricks.
var trumpSuit: String
def main(args: Array[String])
Trick # 2 South leads with the 8 of Clubs West plays the 7 of Clubs North plays the 10 of Clubs East plays the Queen of Diamonds North takes the trick.
class Card(val value: Int, val suit: String)
cardsvariable, as in Bid.scala.
val cards: Set[Card]holds the cards for a given Player.
def add(card: Card): Unitadds a Card to this Hand.
def remove(card: Card): Unitremoves a Card from this Hand.
Setin the Scala API to find out how to add and remove values from a Set. The operations you need are near the top of the list.
def select(suit: String): Option[Card]looks for a Card of the given suit in this Hand. If found, return
Some(card); if not found, return
None. You can use this method as follows:
val hand: Handto hold cards
def deal(players: List[Player])gets cards from the CardDeck, shuffles them, and deals 13 cards to each of the four Players.
def take(card:Card): Unitreceives a
def play(suitLed: String): Card"plays" a card by removing it from this Player's Hand and returning it.
suitLedshould be one of the four suits, or
"lead"means this player leads the trick, and can play any randomly chosen card.
BridgeGameobject which suit is trump); else
We will be running tests on all the methods mentioned above, except
main, which we will test "manually." Therefore, be sure that all your methods are in the right places, spelled and capitalized as shown, and have the correct parameter types and return types.
Please name your file
.scalafile, to Canvas by 6am next Friday, September 27. Decide which of you is going to turn in the assignment, and make only one submission for the two of you. Make sure both of your names are in comments at the top of each file.