Finding Fish Card Game V2 (Base Code Available)
Description
To do this, we will provide code that lets us simulate a deck of cards and players. If you are unfamiliar with playing cards and card games, please see our brief introduction to card games.
We have provided code that does the following:
- Create and shuffle a deck of cards. Print the cards in the deck.
- Create 4 players: Player 1, Player 2, Player 3, and Player 4.
Part 1
Implement the following part of the game:
- Each player takes turns drawing a card from the deck until there are no cards in the deck. Print the line
"Player {X} drew a card"when this happens. - Print out the cards in the hand of each player in sorted order. When printing the cards, group them by suit, and sort them by rank. The suits can be in any order. For this example, all
♣cards are together and sorted, all♦cards are together and sorted, etc.
Part 2: Trick Taking
Now that the game is set up, let’s play! The game will be played as a series of rounds called“tricks”.
- Players can play a card. This means that they remove the card from their hand and place it on the table.
- A“trick”is complete when all four players play a card.
The game starts by picking one player to play first. These players will play each trick as follows:
- The selected player plays a random card from their hand. This is the starter.
- Every following player plays a card from their hand. This card must be the same suit as the starter. You can choose any valid card in this step. Do not worry about player strategy.
- If a player does not have any cards in their hand of the same suit as the starter, they may play any card.
- Print out each player and the card that they played, using the message
"Player {X} played {Card}". - The winner is the player who played the card with the highest rank card that is also the same suit as the starter.
- Print the name of the winner. The winner of this trick is now the starting player for the next trick.
- This is repeated until all of the players have no cards in their hands, then the game ends.
For this part of the problem, simulate an entire game. There should be 13 rounds total in the game. You can make the players play any card they want that follows the rules. Do not worry about strategy.
这道题是一个典型的扑克牌模拟题,核心是围绕 Card、Deck、Player 三个对象完成发牌、排序和每轮 trick 的出牌流程。Part 1 需要先把 52 张牌洗牌后按轮流方式发给 4 位玩家,并按“先花色、后点数”的规则输出每个人手牌;Part 2 则要继续模拟 13 轮出牌,每轮由起始玩家先随机出牌,后续玩家尽量跟同花色,若没有同花色则可任意出牌,并根据同花色中最大点数判断赢家。实现时重点在于对象建模、列表操作、牌面排序规则以及按回合维护当前起始玩家。