[Newbies] Where do I put it?
Ron at USMedRec.com
Mon Mar 5 16:20:39 UTC 2007
Although I think I'm following your questions, I still may not be.
For me it is ok to have a deck. The deck holds onto cards. Each instance
of card is a card that has attributes. Symbols are good for setting the
instance variables of the cards. You could have a method on deck #shuffle,
that sets the order of the cards. And the cards themselves should be based
on a factory in your game. The deck would define the available symbols and
cards, (so you could have games like pinochle), and the game will select the
appropriate deck to use. That factory on games could be reused and
subclassed to make it easier to implement, esp. since the method shuffle
will work for any deck.
cards -> orderedCollection of Card
deckType -> yourDeckTypeSymbol
deckRules -> instace of CardFactory based on yourDeckTypeSymbol
"get a new deck from the deckRules"
self cards: self deckRules shuffle.
gameName -> name of game
deck -> instance of deck
"return the type of deck needed for this game"
class >> forDeckType: aDeckType
"return subclass of factory based on aDeckType"
^self allSubclasses detect: [:aCardFactory |
aCardFactory deckType = aDeckType
"return a collection of cards in random order"
randomGenerator := SecureRandom new.
myCards := self cards copy.
results := OrderedCollection new: myCards size.
[myCards isEmpty] whileFalse:
[results add: (myCards remove: (myCards at:
((randomGenerator next)\\myCards size) + 1)]
CardFactoryAbstract subclass: CardFactory52CardStandardDeck
cards -> orderedCollection of 52 standard cards
class >> deckType -> #standard52Card
class >> deckContentSymbols
"return a group of symbols that represent the contents of the deck"
"use class symbols to add all cards to deck"
I just wrote all this off the top of my head and didn't test any of it, and
I didn't include all the code you need. I guess I'm just giving you a
pattern that will work, but that leaves you plenty to learn on your own. I
tried to make it simple, but I've been told that I don't do that very well.
So if you need a more detailed explanation I can go over each step in my
thinking, please don't be afraid to ask. If you like we can continue this
conversation offline, either way works for me.
> From: Blake
> Sent: Monday, March 05, 2007 3:38 AM
> > Just some quick thoughts. In the real world a deck of cards is just
> > that. There is no meaning in the cards themselves. Instead the meanings
> > are in
> > the rule book that comes with the game that you are playing. Also there
> > is no value in a card, but in the hand, or best hand out of possible
> > hands in the cards that you are dealt.
> Precisely. That's why nothing is in the deck or card to say that (e.g.) a
> Jack is worth "10" or that an ace is "high".
> > Does that help?
> Well, it's nice to know my overall thinking is right (for the value of
> "right" comprised of "Ron agrees with me"<s>). Maybe I can phrase the
> question more clearly now.
> The identity of an inidivual card is its symbol (or symbol set).
> In a standard deck, you have a rank and suit, like "Ace" and "Spades".
> In a tarot deck, you'd have the same, and also the trumps, like "The Fool"
> and "The Hanged Man".
> In a Magic deck, you'd have the name, the type, the mana cost, the
> strength, the defense, the special rules and the "color" text.
> So, we have these symbols--#Ace, #TheFool, #Plains--and my design has them
> defined as part of the deck class.
> The symbols have to be defined at the game level, for sure. The game needs
> to be able to evalulate hands, as you point out. I suppose they don't
> really need to be defined at the deck or card level, except in such a way
> that a particular card or group of cards can be identified. (So if, for
> example, I'm playing Go Fish, I have to be able to identify that a player
> has a Queen, and also to be able to lay down all my Queens when I have
> At the same point, below the game and above the deck, there would seem to
> be some value in having the symbols available. A standard deck, or
> variants composed of just those cards, is used for thousands of games.
> Poker, solitaire, bridge, war, go fish, crazy eights, etc., all use the
> same deck. Some remove cards, like pinochle, some use multiple decks so
> that it's harder to "cheat" (like blackjack).
> Now, maybe I'm wrong on this and it should be regarded as a concidence
> that War, Poker and Bridge all use the same cards, since the cards don't
> have the same meanings. A particular user interface object could still
> treat the cards as the same.
> So, maybe that's the answer: They aren't really the same cards in the
> context of a program, so they should be made at the game level.
More information about the Beginners