Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Help with Deck of cards assignment and getting it to deal... Date: Thu, 04 Sep 2014 10:55:18 -0400 Organization: A noiseless patient Spider Lines: 38 Message-ID: References: <53de8cd5$0$299$14726298@news.sunsite.dk> <53dea33b$0$292$14726298@news.sunsite.dk> <53f3c592$0$300$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 4 Sep 2014 14:55:22 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="14874"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18u27dkVYt5W0y7QDhZuluO" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 In-Reply-To: Cancel-Lock: sha1:i/wUXci8yHti+auvj9xmMeLY/A0= Xref: csiph.com comp.lang.java.programmer:29908 On 9/4/2014 10:14 AM, Chris Uppal wrote: > [... about Comparable/Comparator for Cards ...] > > Yes. Or a bunch of 'em for commonly occurring situation (Ace high, Ace low, > ...). Though I'd be inclined to skip the predefined interfaces altogether > (for cards) since the comparison is more likely to be between /hands/. It depends on the game at, er, hand. There's been much mention of Poker in this thread, a game in which hands are in fact compared (but not in a way Comparable/Comparator can always model). But games like Bridge do not compare hands, though they compare cards. ... and the comparison is not amenable to Comparable. For example, if the Ace of Spades, King of Spades, seven of Clubs, and four of Hearts are played to one trick, which card ranks the highest? We can infer that it's not the King of Spades, but any of the other three cards might be the one that takes the trick: - The Ace wins if either it or the King was led first and neither Hearts nor Clubs are trumps, or if Spades are trumps, - The seven wins if Clubs are trumps, or if it was led first and neither Spades nor Hearts are trumps, - The seven wins if Hearts are trumps, or if it was led first and neither Spades nor Clubs are trumps. To implement this properly, I think you'd need a suite of different Comparators: One for each possible first-led suit, and one for each possible choice of trump suit. (Some economies are possible: The Comparator for a no-trump contract with a Spade lead would give the same result as that for a Spades contract with a spade lead, so I think you'd only need sixteen different Comparators, not twenty.) Tomorrow, we'll discuss Slap-Jack. ;-) -- esosman@comcast-dot-net.invalid