StackedDeck

StackedDeck is a ZISC that operates on a stack of playing cards by drawing and evaluating poker hands.
== Memory Model ==
During execution, a StackedDeck program has access to three unbounded, global stacks. These are referred to as the Deck, the Discard Pile, and the Sleeve. 
All three of these stacks contain playing cards (Cards), each of which has a Rank and Suit.
Possible Suits include Spades, Diamonds, Clubs, and Hearts.
Possible Ranks include 2, 3, 4, 5, 6, 7,
8, 9, 10, Jack, Queen, King, and Ace.
== Program Structure ==
A StackedDeck program is written as 0 or more whitespace-separated Cards, describing the initial state of the Deck. 
Each Card will be pushed to the Deck before the program begins evaluating; Cards are pushed back-to-front, meaning
that the first card that appears in the program will be at the top of the Deck. The Sleeve and Discard Pile are always initially empty.
Each individual card is written as the first letter of its suit followed by the first character in its rank. (except 10)
Valid cards are as follows: 
 SA SK SQ SJ S10 S9 S8 S7 S6 S5 S4 S3 S2
 DA DK DQ DJ D10 D9 D8 D7 D6 D5 D4 D3 D2
 CA CK CQ CJ C10 C9 C8 C7 C6 C5 C4 C3 C2
 HA HK HQ HJ H10 H9 H8 H7 H6 H5 H4 H3 H2
Additionally, any sequence of 0 or more cards may be wrapped in parenthesis to group them together. When doing this, a positive natural number
can be written afterwards to indicate a repetition.
For example:
 D9 (D8 D7)2 D6
is the same as writing
 D9 D8 D7 D8 D7 D6
Parenthesis like this can be nested and work as you'd expect. And, again, in both situations here, D9 is at the top of the Deck.
Finally, line comments can be written using //, all characters following it will be ignored until the next line. 
Block comments can be written with /* */, all characters between will be ignored.
== Execution ==
Once the program has been parsed and the Deck is populated with cards, the main execution loop will begin, which goes like so:
# Pop 5 cards off of the Deck and add them to a temporary "Hand" buffer. If fewer than 5 cards are in the Deck, pop as many as possible.
# If the hand buffer is empty, halt the program.
# Determine the "hand type" of the cards in the Hand buffer.
# Execute cards in the Hand buffer left-to-right*, skipping cards that aren't relevant to the determined hand type.
# Push all cards in the Hand buffer to the Discard Pile right-to-left; The leftmost card will be at the top of the Discard Pile.
# Clear the Hand buffer and repeat.
*The card at the top of the Deck will be the left-most card, other cards will follow left-to-right.
=== Hand Types ===
After 1-5 cards have been put into the Hand buffer, a "hand type" is determined. This hand type determines which cards will be executed.
The order of cards in a given hand never affects its hand type.
The following table describes every hand type in StackedDeck. In examples, ** indicates a card that will not be executed— 
it can be any card or not present at all.
Name 	Description 	Minimum Number of Cards in Hand	Example Hands
Five of a Kind 	Five cards have the same rank. All cards executed. 	5 	S5 D5 C5 C5 H5
Flush 	Five cards have the same suit. All cards executed. 	5 	C3 C4 CK CJ C10
Full House 	Two cards have the same rank, three other cards have matching ranks. All cards executed. 	5 	C3 S3 DK CK DK
Straight 	Five cards have consecutive ranks. All cards executed. Aces can be considered consecutive to either 2 OR King (But not both at the same time) 	5 	S8 D7 S6 C5 D4 D5 C4 C3 H2 HA HA SK SQ DJ H10 H3 S2 SA DK HQ (This one is invalid)
Four of a Kind 	Four cards have the same rank. These four cards are executed. 	4 	H4 C4 D4 H4 **
Two Pair 	Two cards have the same rank, two other cards also have matching ranks. These four cards are executed. 	4 	D5 H5 H2 C2 **
Three of a Kind	Three cards have the same rank. These three cards are executed. 	3 	H4 D4 D4 ** **
Pair 	Two cards have the same rank. These two cards are executed. 	2 	S4 D4 ** ** **
High Card 	Applies if no other hand types apply; executes the card with the highest rank and nothing else. Ranks are ordered Ace > King > Queen > Jack > 10 > ... > 2	1 	CA ** ** ** **
=== Card Execution ===
After a hand type has been determined, all applicable cards will be evaluated from left-to-right. A table of cards and their effects is included below.
 Card Effects
Card 	Effect on Execution 	Card Value
Ace of Spades (SA) 	No-op; Does nothing. 	1
King of Spades (SK) 	Prevents this hand from being added to the Discard Pile. 	13
Queen of Spades (SQ) 	TODO 	12
Jack of Spades (SJ) 	TODO 	11
10 of Spades (S10) 	TODO 	10
9 of Spades (S9) 	TODO 	9
8 of Spades (S8) 	TODO 	8
7 of Spades (S7) 	TODO 	7
6 of Spades (S6) 	TODO 	6
5 of Spades (S5) 	TODO 	5
4 of Spades (S4) 	TODO 	4
3 of Spades (S3) 	TODO 	3
2 of Spades (S2) 	TODO 	2
Ace of Diamonds (DA) 	Marks the card to its right to not execute. (No-op if target is an Ace) 	1
King of Diamonds (DK) 	Clears the Discard Pile. 	13
Queen of Diamonds (DQ)	TODO 	12
Jack of Diamonds (DJ) 	TODO 	11
10 of Diamonds (D10) 	TODO 	10
9 of Diamonds (D9) 	TODO 	9
8 of Diamonds (D8) 	TODO 	8
7 of Diamonds (D7) 	TODO 	7
6 of Diamonds (D6) 	TODO 	6
5 of Diamonds (D5) 	TODO 	5
4 of Diamonds (D4) 	TODO 	4
3 of Diamonds (D3) 	TODO 	3
2 of Diamonds (D2) 	TODO 	2
Ace of Clubs (CA) 	Marks the card to its right to execute 1 extra time. (No-op if target is an Ace)This can cause a card to execute even if it's not part of the hand type. 	1
King of Clubs (CK) 	Read the value of the card to the right; pop that many cards from the Discard Pile and push them to the Deck. The popped cards are treated as one unit, rather than several individual pops, so the card order will be preserved.	13
Queen of Clubs (CQ) 	TODO 	12
Jack of Clubs (CJ) 	TODO 	11
10 of Clubs (C10) 	TODO 	10
9 of Clubs (C9) 	TODO 	9
8 of Clubs (C8) 	TODO 	8
7 of Clubs (C7) 	TODO 	7
6 of Clubs (C6) 	TODO 	6
5 of Clubs (C5) 	TODO 	5
4 of Clubs (C4) 	TODO 	4
3 of Clubs (C3) 	TODO 	3
2 of Clubs (C2) 	TODO 	2
Ace of Hearts (HA) 	TODO 	1
King of Hearts (HK) 	Read the value of the card to the right; pop that many cards from the Discard Pile. 	13
Queen of Hearts (HQ) 	TODO 	12
Jack of Hearts (HJ) 	TODO 	11
10 of Hearts (H10) 	TODO 	10
9 of Hearts (H9) 	TODO 	9
8 of Hearts (H8) 	TODO 	8
7 of Hearts (H7) 	TODO 	7
6 of Hearts (H6) 	TODO 	6
5 of Hearts (H5) 	TODO 	5
4 of Hearts (H4) 	TODO 	4
3 of Hearts (H3) 	TODO 	3
2 of Hearts (H2) 	TODO 	2
=== Clarifications ===
* If a card refers to the card to its left or right, it's referring to adjacent cards in the hand buffer. This will wrap around the edge of the hand buffer.
== Examples ==
TODO