Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: Help with Deck of cards assignment and getting it to deal... Date: Mon, 04 Aug 2014 20:03:04 -0400 Organization: A noiseless patient Spider Lines: 153 Message-ID: References: <53de8cd5$0$299$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 5 Aug 2014 00:03:11 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b896cb427f8c4d19d14880347aa9d6ce"; logging-data="21765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IVHnB+EiTioOH9cb09o+QuAwjP/tijhQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.7.0 In-Reply-To: Cancel-Lock: sha1:GqT0PcUuX/C8ybA2yt0VjqPJuBM= Xref: csiph.com comp.lang.java.programmer:29560 On 08/04/2014 08:14 AM, Eric Sosman wrote: > On 8/3/2014 5:19 PM, Jeff Higgins wrote: >> On 08/03/2014 04:49 PM, Eric Sosman wrote: >>> On 8/3/2014 3:26 PM, Arne Vajhøj wrote: >>>> [...] >>>> I must admit that I can not follow you. >>>> >>>> The fact that different games may use a different ordering is >>>> not an argument against Comparable<>. >>>> >>>> Comparable<> is not the one and only ordering. Comparable<> is >>>> just the natural ordering. It is perfectly valid to have a >>>> Comparable<> with the natural ordering and a bunch of >>>> Comparator<> to handle the context specific orderings. >>> >>> Although one could select different Comparators for different >>> games -- one for Ace-low, say, and another for Ace-high -- there >>> is no way a Comparator could work for "Ace-either" games like Poker >>> (and certainly not for "Ace-both" games like high-low Poker!). Like >>> Comparable, Comparator reflects a _total ordering_ on the objects it >>> compares, and a total ordering must be transitive: >>> >>> If X < Y and Y < Z then X < Z, for all X,Y,Z. >>> >>> In Poker, one can have >>> >>> Ace < Five and Five < Ten but Ten < Ace >>> >>> ... violating transitivity, so the ranks do not follow a total order. >> >> In my proposed interface Ace is a valid Rank but Five and Five is not. > > What rank, then, does the Five of Spades have? Does the word Rank connote a hand of cards to you? Or that the Rank of a Card has the two attributes, face value and suit? For me the rank(Rank) of a Card is its face value, Ace, Two - Ten, Jack, Queen, King. Have you looked at the interfaces I've proposed? I will reproduce them below for reference. I'm not especially proud of the wording of some of the Javadoc comments, but we can leave that for later. The Five of Spades would be a Card. A Card has a Comparable Rank(its face value), and a Comparable Suit,(its Suit) so in this case its Rank is Five and Suit is Spades. In my card game, which I haven't produced, much less tested, I ask to compare two Cards: my Cards compareTo calls its Ranks compareTo method which looks in the rule book and discovers that at this point in this particular game your Five is greater than my Four, Cards compareTo then calls its Suits compareTo which determines that at this point your Spades is greater than my Club, Cards compareTo then looks in the rule book and determines that at this moment in this game my Card is greater than your Card. Since this is my one card one hand game I win. Nowhere have I described a Comparable Hand of cards - which seems to me to to be what you are arguing about - or a Game of Cards [snip] > > Your Card class will be more easily used if it implement the > > java.lang.Comparable interface This statement may very well be wrong because Scott's Card class is not Jeff's Card class. But not because of some total ordering that Comparable requires. If you consider that weaseling - so be it. > > is false for many card games. package scratch; /** * The face value of a {@link Card}. * * Rank specifies one of 13 distinct, * implementation defined values and their order. * * The default values and order for Rank are: * Ace, Two through Ten inclusive, Jack, Queen, King. * * @author jeff * */ public interface Rank extends Comparable { } package scratch; /** * The suit of a {@link Card}. * * Suit specifies one of an implementation defined * number of distinct values and their order(if any). * * The default values and their order(highest to lowest) * for Suit are: Spades, Hearts, Diamonds, Clubs. * * @author jeff * */ public interface Suit extends Comparable { } package scratch; /** * A playing card. * * @author jeff * */ public interface Card extends Comparable { /** * Returns one of the 13 distinct values represented * in the implementation of the {@link Rank} interface. * * @return the Rank of this Card. */ Rank getRank(); /** * Returns one of the distinct values represented * in the implementation of the {@link Suit} interface. * * @return the Suit of this Card. */ Suit getSuit(); } package scratch; /** * An ordered set of playing {@link Card}s. * * @author jeff * */ public interface Deck extends Iterable { }