User:Jpusztai/sandbox/Hungarian Rummy

Hungarian Rummy is a regional card game that can be played by two to four players.

It follows the conventions of all rummy games, namely the arrangement of a player's dealt cards into melds ("terz") of three or more cards, and a A meld can be either a set of cards of the same rank (e.g. three or four Queens of unique suits), or a sequence (commonly called a "run") of cards of the same suit, similar to a straight flush in poker.

Decks and jokers
Hungarian Rummy is played with two combined 52-card decks, plus jokers that serve as wild cards (with some constraints on their use, explained below). Traditionally, two jokers are included for two players, and four jokers are employed for three or four players, making the odds of drawing or being dealt wild cards roughly consistent.

Rounds and dealing
A game consists of a predetermined number of rounds. A "short game" is traditionally seven rounds, a normal game consists of ten rounds. One players is designated as the scorekeeper for the entire game, and is normally the dealer for the initial round. The deal passes clockwise in each subsequent round. A round of Hungarian Rummy begins as follows:
 * The dealer thoroughly shuffles the two decks together, plus the appropriate number of jokers, then places the shuffled deck in front of the player to his right.
 * The player to the right lifts approximately half of the cards from the top of the deck, then flips the bottommost card of this partial deck, and places it face-up in the center of the table. This face-up card is designated as the community card.
 * The player making the cut then places the partial deck in hand face down, overlapping and perpendicular to the community card, such that the community card remains recognizable during the course of play. This pile is now the stockpile for drawing new cards during a round.
 * The community card cannot be a joker, thus, if the flipped card is a joker, the cutting player is entitled to keep it as their first dealt card, which the dealer must adjust for in the deal count. If subsequent flipped cards are also jokers, they are inserted randomly back into the top half of the deck.
 * After the stockpile and community card is established, the dealer takes the bottom half of the cut deck and deals 14 cards to each player. The traditional method of dealing is in pairs i.e. seven deals of two cards each to each player.
 * The player to the dealer's left is always dealt one extra card, as he/she will make the first discard to begin the round. Traditionally, this extra card is the very first card dealt i.e. in lieu of a pair of cards, the starting player receives a one-time deal of three cards.
 * Any excess cards after the dealing is completed are placed on the stockpile. Conversely, if the dealer runs out of cards during the deal, the necessary number of extra cards are dealt from the top of the stockpile.

Request for new deal
After the initial deal but before play begins, any player with four pairs of duplicate cards, or three pairs of duplicates plus a joker, may request a new deal. In this event, each player is allowed to keep up to five (5) cards, which the dealer must adjust for during the re-deal, such that each player begins the round with 14 cards (15 for the starting player to the dealer's left).

Game play
The objective of each round is to be the first player lay off all of one's cards (see below). A round begins when the designated starting player (the one immediately to the left of the dealer, and who possesses one extra card than all the other players) initializes the discard pile with an undesired card. The discard pile is traditionally formed adjacent to the stockpile. All subsequent turns requires the player to draw a card from the stockpile, pick up the card on the top of the discard pile (i.e. that was most recently discarded by the player to his right), or draw the visible community card. In the latter cases, cards not drawn from the stockpile must immediately be played. Further, drawing the community card is only permitted if the player can immediately win the round via a rummy (see below). A player's turn officially ends when they discard a card. Exceptions can be made in friendly games with inexperienced players, but "do overs" (e.g. discarding an unintended card, overlooking an opportunity to lay off cards, or even win the round) are generally not permitted. Further, a discard is always required. This is of particular importance when winning a round, as a card must alway be available for a "final" discard after laying off the final cards. If the stockpile is depleted before the round is won, the discard pile is shuffled and forms the new stockpile. Special Conditions for the First Discard Cycle In the first discard cycle only, the card available to a player via the discard pile may be picked up without the requirement to play it immediately, thus providing the opportunity to "swap" one of the dealt cards for a more desirable one. Also in the first discard cycle, a player is not permitted to use the community card, nor win the round via a rummy, assuming they had been dealt a perfect rummy hand. Laying Off Cards There are two methods to lay off cards:Forming valid melds and placing them in full view of other players on the tableValidly attaching cards to any melds already on the table, regardless of which player originated them.Opening Layoff Point Count The opening layoff for every player is unique - the point total of all the cards laid off must be at minimum 51 points. For these purposes, face cards count as 10 points, aces in a run count as 1 or 10 depending on the position they are played in (e.g. 1-2-3 counts as 6 points, whereas Q-K-1 counts as 30). Aces used in sets of three or four count as one point (e.g. 1-1-1-1 counts as 4) Jokers used as wildcards in runs count as the card position they are substituting for (e.g. 5-Joker-7 equals 36 points) and when used in sets, as the natural cards in the sets e.g. 5-5-Joker = 15 points). For example, a set of three 10s or face cards, plus a set of sevens or a run of 6-7-8 would equal 51. Laying off more than 51 points in the opening layoff is permitted. If the initial layoff is a rummy, the 51 point requirement is waived. Valid Melds A meld is three or more cards following the common conventions of rummy games, with the following exceptions.Two jokers cannot be used in a set e.g. Two jokers cannot be used in a set Using the Community Card The community card can be used by any player during their turn, in lieu of drawing a card from stock or picking up a card from the discard pile. The community card can only be used if the player can can lay off all their cards in a rummy.

Discards A player's turn, including their final turn, must end with a discard. Laying Off Scoring Unlike most rummy games, a player's melds has no bearing on the score, and the goal is to win the game with the lowest score, not the highest. Scoring for each round is based on the card value remaining in each losing player's hand when the winning player ends a round by laying off all their cards. The player winning the round is scored -20 (negative) points  If a round ends in a rummy, all