|
Jason Olson has some comments about the Poker Deck I developed and I am starting to agree with some of them. Not that the integrated Hand is bad, but more that the integrated Hand is not tightly integrated enough to be sufficiently useful. So what am I going to do about it? Well, I'm going to fix it darnit. Or better, yet not fix it quite yet, but explain the names a bit better. I'll start by taking a few sample definitions with respect to where cards are located in several games.
- Poker
- Initial Deck - 52 Cards - Cards are dealt with one hand per player
- Hands - 5 Cards at a time in general - Cards can be discarded and new cards retrieved.
- Discard Pile - A pile where all dealt cards that get discarded go, and after the Initial Deck is finished, Cards can be reshuffled into the Initial Deck
- Solitaire
- Initial Deck - 52 - ((7*8)/2) - or basically 52 - 28 where 28 is the initial set of cards in the 7 tiers
- 7 Tiers - This is where the game is played
- Top of Deck - 1 Card that you can see, maybe three, depending on how the settings are laid out
- Discard Pile - Cards that have been moved from the playable hand back to the pile.
- 4 Suit Stacks - Where you place all of the cards that will win you the game.
- Magic the Gathering
- Two Initial Decks - Ouch, does our deck fail at this point? Kind of, but I'll fix that.
- 1 Hand per player
- 1 Discard pile per player
- Many Board Locations for placing cards
Now, all we need to do is define the appropriate definitions and everything works. What is a Deck? Well a deck is the initial set of cards. It is the source of cards. A deck in Poker is 52 cards, Solitaire, the same deck. What about Magic the Gathering? Well, the deck is the same, but it is comprised of cards from two players, so you logically have two decks, but from an abstract standpoint the deck is the set of all other decks. Using some set theory here isn't but so bad eh ;-)
What is a Hand? Well, a hand is a pile of cards. A hand holds onto cards, but it doesn't own them. That is the job of the deck. The deck controls the entire process of making sure all cards are properly initialized and then placed in their initial spots. The current Deck does this well, but there is some work left. Just as the Card definition is meant to be overriden and slightly changed, so is the Deck. With that in mind I'll be releasing a new Deck that offers a number of extra features and is consistent with this new model I've defined. The new process would be defined as follows:
Deck<StandardCard> deck = Deck<StandardCard>.CreateDeck( new HandInfo[] { new HandInfo(“Initial Deck“, 0, StandardCard.StandardDeck), new HandInfo(“Hands“, 0, null), new HandInfo(“Hands“, 1, null), new HandInfo(“Hands“, 2, null), new HandInfo(“Hands“, 3, null), new HandInfo(“Discard“, 0, null) } );
What does the above do? Well, it creates a deck of cards with several named hands. One of the hands is the InitialDeck and it contains a set of StandardDeck cards. You can pass in more decks if you need to. The Hands are a single collection of hands, each indexed by a different number 0 through 3. Finally there is a Discard pile. All of the commands on Deck now manage the passage of items between hands. Remember, a Deck should be contained within an Engine, so that the user never has direct access to the Deck. The Deck still has the basics of internal protection, but it is truly protected by the Engine itself.
deck.Shuffle(“Initial Deck“, 0); // That'll handle your shuffling deck.Deal(“InitialDeck“, 0, “Hands“, 0, 5); // Deal 5 cards to the first hand deck.Deal(“InitialDeck“, 0, “Hands“, 1, 5); // Deal 5 cards to the second hand deck.Transfer(”Hands”, 0, “Discard”, 0, 3); // Transfer card 3 from Hands 0 to Discard pile
I think just about everything is possible with this feature set and the deck is a bit cleaner. It can still protect it's children and hold their hands (terrible association). The diagram shows the process in action and is described as follows:
-
Deck is the init class. Everything happens through Deck.
-
Hands is an indexed property that is indexed by Name or by Name, Offset combo. By Name defaults to the 0th hand of that name or the default hand.
-
Named Hand is a collection of the various hands. Sometimes this will be a list of length 1, other times it will be a larger list.
-
Offset 0 is the default hand
-
Offset 1-N are the N additional offset hands in the named hand.
I am hoping this makes logical sense to everyone. I can easily show some games, including Solitaire and Poker being played using this new deck and rules.
|
|