Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29560
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Help with Deck of cards assignment and getting it to deal... |
| Date | 2014-08-04 20:03 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <lrp6vv$l85$1@dont-email.me> (permalink) |
| References | (4 earlier) <lrm0rl$c1f$1@dont-email.me> <53de8cd5$0$299$14726298@news.sunsite.dk> <lrm78o$t48$1@dont-email.me> <lrm90o$aem$1@dont-email.me> <lrnter$am9$1@dont-email.me> |
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> Rank(its face value),
and a Comparable<Suit> 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<T> 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<Rank> {
}
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<Suit> {
}
package scratch;
/**
* A playing card.
*
* @author jeff
*
*/
public interface Card extends Comparable<Card> {
/**
* 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<Card> {
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help with Deck of cards assignment and getting it to deal... Scott Dunning <scottwd01@gmail.com> - 2014-08-01 18:16 -0700
Re: Help with Deck of cards assignment and getting it to deal... Roedy Green <see_website@mindprod.com.invalid> - 2014-08-02 01:42 -0700
Re: Help with Deck of cards assignment and getting it to deal... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-02 10:19 +0000
Re: Help with Deck of cards assignment and getting it to deal... Roedy Green <see_website@mindprod.com.invalid> - 2014-08-03 15:54 -0700
Re: Help with Deck of cards assignment and getting it to deal... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-04 13:00 +0000
Re: Help with Deck of cards assignment and getting it to deal... Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 17:48 -0400
Re: Help with Deck of cards assignment and getting it to deal... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-20 10:48 +0100
Re: Help with Deck of cards assignment and getting it to deal... Arne Vajhøj <arne@vajhoej.dk> - 2014-09-07 21:42 -0400
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-09-07 22:04 -0400
Re: Help with Deck of cards assignment and getting it to deal... Arne Vajhøj <arne@vajhoej.dk> - 2014-09-07 22:08 -0400
Re: Help with Deck of cards assignment and getting it to deal... Mike Amling <mamling@chaff.us> - 2014-08-03 07:38 -0500
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-03 10:23 -0400
Re: Help with Deck of cards assignment and getting it to deal... lipska the kat <lipskathekat@example.com> - 2014-08-03 18:52 +0100
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 14:16 -0400
Re: Help with Deck of cards assignment and getting it to deal... lipska the kat <lipskathekat@example.com> - 2014-08-03 19:21 +0100
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 14:38 -0400
Re: Help with Deck of cards assignment and getting it to deal... lipska the kat <lipskathekat@example.com> - 2014-08-03 19:41 +0100
Re: Help with Deck of cards assignment and getting it to deal... Mike Amling <mamling@chaff.us> - 2014-08-03 16:05 -0500
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 11:08 -0400
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-03 11:41 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 13:25 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 13:36 -0400
Re: Help with Deck of cards assignment and getting it to deal... David Postill <david.postill@gmail.com> - 2014-08-04 09:00 +0200
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 13:47 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 13:52 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 14:10 -0400
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-03 15:00 -0400
Re: Help with Deck of cards assignment and getting it to deal... Arne Vajhøj <arne@vajhoej.dk> - 2014-08-03 15:26 -0400
Re: Help with Deck of cards assignment and getting it to deal... lipska the kat <lipskathekat@example.com> - 2014-08-03 20:34 +0100
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-03 16:49 -0400
Re: Help with Deck of cards assignment and getting it to deal... Arne Vajhøj <arne@vajhoej.dk> - 2014-08-03 17:01 -0400
Re: Help with Deck of cards assignment and getting it to deal... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-04 20:32 +0100
Re: Help with Deck of cards assignment and getting it to deal... Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 17:45 -0400
Re: Help with Deck of cards assignment and getting it to deal... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-20 10:50 +0100
Re: Help with Deck of cards assignment and getting it to deal... Brixomatic <brixomatic@yahoo.com> - 2014-08-31 10:17 +0200
Re: Help with Deck of cards assignment and getting it to deal... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-09-04 15:14 +0100
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-09-04 10:55 -0400
Re: Help with Deck of cards assignment and getting it to deal... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-09-04 16:12 +0100
[OT] Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-09-04 15:05 -0400
Re: Help with Deck of cards assignment and getting it to deal... Gene Wirchenko <genew@telus.net> - 2014-09-05 10:03 -0700
Re: Help with Deck of cards assignment and getting it to deal... Arne Vajhøj <arne@vajhoej.dk> - 2014-09-07 21:45 -0400
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-09-07 22:13 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 17:19 -0400
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-04 08:14 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-04 20:03 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-04 20:29 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 15:45 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 16:01 -0400
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-03 17:05 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 17:37 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 18:19 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 18:34 -0400
Re: Help with Deck of cards assignment and getting it to deal... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-03 20:37 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 20:40 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 20:49 -0400
Re: Help with Deck of cards assignment and getting it to deal... Jeff Higgins <jeff@invalid.invalid> - 2014-08-03 18:09 -0400
Re: Help with Deck of cards assignment and getting it to deal... Roedy Green <see_website@mindprod.com.invalid> - 2014-08-04 18:43 -0700
Re: Help with Deck of cards assignment and getting it to deal... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-05 11:19 +0100
Re: Help with Deck of cards assignment and getting it to deal... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-05 11:28 +0100
Re: Help with Deck of cards assignment and getting it to deal... lipska the kat <lipskathekat@example.com> - 2014-08-31 17:31 +0100
csiph-web