Python代写:COMP10001 Phased Out

代写一款叫Phased Out的纸牌游戏。

Game Description

In this project, you will implement a program that plays a game called “Phased Out”, which is a variant of Phase 10, which is in turn a variant of rummy. Why a variant? Because Tim can’t help himself … or more seriously, because Tim wanted to come up with a version that was more compatible with a computational implementation (e.g. not too long, and suitably algorithmically complex).

We will play Phased Out with two standard decks of 52 cards each (i.e. 104 cards in total). Each card has a “suit” (Spades, Clubs, Hearts, Diamonds) as well as a “value” (numbers 2 to 10, as well as Jack, Queen, King and Ace).

The Rules of Phased Out

Overview

Phased Out is a 4-player game where the objective is to be the first to complete a series of “phases” by placing particular combinations of cards on the table. The game is broken down into a series of “hands”, in each of which, the 4 players are dealt 10 cards each from a 104 card deck, and take it in turns either drawing a card from the face-down deck, or picking up the top card from the discard pile. When they have the requisite cards to complete a given phase, on their turn, they place those cards on the table, and optionally place any remaining cards on any set that has been placed on the table (their own or sets of other players). For a given hand, play continues until one of the following occurs: (1) a player places all of their cards on the table; (2) the deck is exhausted; or (3) each player has played 50 times. At the point that one of these occurs, players tally up penalty points based on the cards remaining in their hand. The game continues across multiple hands until either: (1) a player has completed all of their phases; or (2) 12 hands have been completed. In the former case, the winner is the player who completed all of their phases (or the player(s) with the lowest point score who have completed all games, in the case of a tie); in the latter case, the player(s) with the lowest point score win.

The full details of the deal, how cards are drawn and played, and how phases work, are outlined in the following sections.

The Deal

The sequence of play is fixed throughout the game (based on clockwise sequence between the players), but the dealing of cards for each phase rotates between players (also clockwise, by one player per deal), and the lead player for each phase also rotates, with the player to the left of the dealer leading. The dealer shuffles the combined deck, deals out 10 cards to each of the 4 players, places the top card of the remaining deck face up in the middle of the table (to form the “discard” pile, and places the remainder of the deck face down next to it).

A Single Turn

On their turn, a player performs the following actions:

  1. picks up either the top card from the discard pile, or the top card from the deck
  2. optionally plays cards from their hand to make up a complete phase. Note that only one phase can be played for a given hand, and that a complete phase must be played at once (i.e. it is not possible to play part of a phase with one play, and the remainder with another play)
  3. assuming that the player has completed their phase for the hand, optionally plays other cards on whatever sets of cards have been played on the table (for any player, including their own sets)
  4. assuming the player still has at least one card left in their hand, they place a single card face up in the discard pile

Phases

The phases that a player must complete are made up of the following card combinations:

  • a “set” of N cards of the same value: N cards of the same value, of any suit (e.g. [‘2S’, ‘2S’, ‘2H’] is a set of 3 cards)
  • a “set” of N cards of the same suit: N cards of the same suit, of any values (e.g. [‘2C’, ‘7C’, ‘7C’, ‘8C’, ‘JC’, ‘QC’, ‘KC’] is a set of 7 Clubs)
  • a “run” of N cards: a consecutive sequence of N cards, based on value (e.g. [‘2S’, ‘3D’, ‘4C’, ‘5D’, ‘6C’, ‘7D’, ‘8H’] is a run of 7 cards); note that, for the purpose of runs, Jacks, Queens and Kings take on the values 11, 12 and 13, resp., and runs cannot wrap around from 13 to 2
  • a “run” of N cards of the same colour: a run of N cards where all cards are of the same colour, as defined by the suit (Spades and Clubs are black, and Hearts and Diamonds are red; e.g. [‘2S’, ‘3C’, ‘4C’, ‘5S’] is a run of 4 black cards)

To win the game, a player must complete the following phases, in the sequence indicated:

  1. Phase 1: two sets of three cards of the same value (e.g. [[‘2S’, ‘2S’, ‘2H’], [‘7H’, ‘7S’, ‘7D’]])
  2. Phase 2: one set of seven cards of the same suit (e.g. [[‘2C’, ‘7C’, ‘7C’, ‘8C’, ‘JC’, ‘QC’, ‘KC’]])
  3. Phase 3: two sets of four cards of the same value (e.g. [[‘2S’, ‘2S’, ‘2H’, ‘2D’], [‘7H’, ‘7S’, ‘7D’, ‘7D’]])
  4. Phase 4: one run of eight cards (e.g. [[‘2S’, ‘3D’, ‘4C’, ‘5D’, ‘6C’, ‘7D’, ‘8H’, ‘9S’]])
  5. Phase 5: one run of four cards of one colour + one set of four cards of the same value (e.g. [[‘2S’, ‘3C’, ‘4C’, ‘5S’], [‘7C’, ‘7S’, ‘7D’, ‘7D’]])

Playing Cards on Sets

Once a player has played the necessary phase for the hand, they may play any number of cards from their hand onto any set that is on the table, consistent with the composition of that set. That is:

  • for a set of three or four, a card of the same value (e.g. ‘2C’ on [‘2S’, ‘2S’, ‘2H’])
  • for a run, a card which continues the sequence (e.g. ‘9D’ on [‘2S’, ‘3D’, ‘4C’, ‘5D’, ‘6C’, ‘7D’, ‘8H’])
  • for a set of cards of a given suit, a card of the same suit (e.g. ‘4C’ on [‘2C’, ‘7C’, ‘7C’, ‘8C’, ‘JC’, ‘QC’, ‘KC’])
  • for a run of cards of a given colour, a card which continues the sequence of that same colour (e.g. ‘6S’ on [‘2S’, ‘3C’, ‘4C’, ‘5S’]

Note that this can only take place once the phase has been completed for the hand. A player may play as many cards as they want in a given turn, including in the case that they played their phase in that turn.

Special Cards

Phased Out includes “Wild” cards (8), in the form of any Ace (e.g. ‘AS’), which can take on any value or suit. The particular value and suit of the wild is determined by the phase they are played as part of, and my be underspecified, e.g. in the case of the run of seven cards [‘2S’, ‘3D’, ‘4C’, ‘AD’, ‘6C’, ‘7D’, ‘8H’], where ‘AD’ is playing the role of a five, but the suit is underspecified. Once played, however, the value/suit of the wild card at the time of play cannot be changed through subsequent plays (e.g. it would not be possible to play ‘5D’ on [‘2S’, ‘3D’, ‘4C’, ‘AD’, ‘6C’, ‘7D’, ‘8H’] and reclassify ‘AD’ as a nine).

Note that, for runs, an Ace can only be played as a stand-in for values 2-13 (i.e. it can’t be used as value 1 or value 14). Additionally, in any given group, there must be at least two “natural” (= non-Wild) cards, e.g. [‘2C’, ‘2S’, ‘AC’] is a valid set of three cards of the same value (3 Twos), but [‘2C’, ‘AS’, ‘AC’] is not, as it is made up of only one natural card.

The End of a Hand

A hand ends when: (a) a player has played all of their cards (meaning they must also have completed a phase), either by discarding their last card, or by playing their last card to a set; (b) the deck has been exhausted; or (c) each player has played 50 times. In the latter two cases, the hand ends at the point that the player who drew the last card discards.

Scoring a Hand

At the end of a hand, the score for each player is determined based on the cards remaining in their hand, as follows:

  • for cards Two up to Ten, the score is the face value of the card (i.e. 2-10, resp.)
  • for the Jack, Queen and King, the score is 11, 12 and 13, resp.
  • for Aces, the score is 25

For example, if a player holds [‘3D’, ‘JC’, ‘AS’] at the end of the hand, their score would be 3+11+25=39.

The player score accumulates over the hands that make up a game.

Bonus Version

The bonus version of the game differs from the basic version in two ways:

  1. the phases can be completed in any order, once each for a given game; the composition of cards when the phase is played determines the type of the phase (e.g. if a player holds two sets of four cards of the same value, but wants to play them as two sets of three cards of the same value, they must first play two sets of three cards, and then play the remaining two cards individually on the respective sets)
  2. Jokers (4) are added to the pack, and used as “Skip” cards - when played, the player nominates one of the other three players to skip on their next turn (meaning they miss that turn); note that if a player has been nominated to be skipped on their next turn already, playing another Skip card on that player has no effect. Additionally, if a Joker ends up on the discard pile, it may not be picked up.