proper use of .java files (layout)

A

Arne Vajhøj

On 12/17/2012 1:28 PM, Lew wrote:
[snip]
If you hard-code certain assumptions, e.g., that there are 52 cards in the deck,
your program will be unable to model many games.

I would argue that a deck is always 52 cards, but that some
games use more than one deck.

Some games do not use all of the deck; some include one or more
jokers. See the section "Modified Deck" in
http://boardgamegeek.com/wiki/page/Standard_Deck_Playing_Card_Games
for several examples.

Jokers has already been discussed.

I would not change the definition of deck because some
games does not use all cards in a deck.

public interface Game {
...
public List<Card> cardsUsed();
}

Arne
 
S

Stefan Ram

markspace said:
I was actually thinking about that. I don't like the idea of trying to
encode most of the values of a face card as enums.

I do not like the idea of designing a card game /before/
I know exactly /which/ card game it is at all. I need to
know the rules of this card game and what exactly has to be
programmed (e.g., human players or also computer [AI]
players?). Only then I start to design.

But often not even then do I do a beforehand OOD. Instead,
I start out procedurally, using OOP only where it is obvious.
Then I start to see OO patterns in the procedural code,
so I then refactor into OOD and eventually arrive at an
»object-oriented program«.

But this is also a question of experience: If I would
already have written similar games, I might be able to
OOD a larger part of the program up-front.
 
G

Gene Wirchenko

[snip]
13 distinct values with an order but no numeric values
seems a perfect fit for enum to me.

An enum does not guarantee an order.

In the Java I use enums have a compareTo method.

And how would you handle the aces?

A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
five-high straight).

Human systems can be remarkably exceptional if I may use the word
in the sense of "having an exception".

Sincerely,

Gene Wirchenko
 
E

Eric Sosman

[snip]

13 distinct values with an order but no numeric values
seems a perfect fit for enum to me.

An enum does not guarantee an order.

In the Java I use enums have a compareTo method.

And how would you handle the aces?

A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
five-high straight).

In some "high-low" games, A-5-4-3-2 can be both a
five-high straight *and* an Ace with four low cards,
possibly winning both the "high" and "low" shares of
the pot.
 
I

infinitum3d

Wow! Lots of great discussion going on here.

This in no way, shape, or form negates or takes away anything from any of the wonderful comments already posted, but let me add some details to help clarify the original post;

As stated in the OP, I consider a deck to be 52 cards with 4 suits. Those suits are Hearts, Clubs, Diamonds, Spades. Aces could be valued as 1 or 11.

I'm not exactly sure what card game I will be programming at this time. I've never done a card game before, so I will start with something extremely minor, perhaps a Memory style game where you have 52 cards face down in 4 rows of 13. You turn them over two at a time and hope for a matching pair (byface/value, ie. 2 of Hearts and 2 of Spades). Maybe I'll start even smaller, with only 16 cards.

Eventually I would like to progress to something like Magic: The Gathering (or the Alchemy droid app) with several hundreds of cards, with various values and abilities.

Thank you all again for your comments. They are extremely helpful.

I3D
 
E

Eric Sosman

Interesting, what do our procedural programmer(s) make of this then.
The OP isn't sure what game he will be programming ....

I suggest you start writing some code

He doesn't know what he wants to do, yet your advice is
"start writing some code?"

Ye flippin' gods.
 
E

Eric Sosman

Yes, start writing code
What do you suggest he does, Sit there twiddling his fingers.

I bet you have a pre-meeting meeting to discuss what to discuss in the
meeting don't you. Ye gods and little Indians, I've battled with the
likes of you all my professional life. I always deliver though because I
get code down and learn from it.

Write code, make mistakes, refactor, reiterate ... LEARN

Or sit on your hands lamenting your inability to get past the first
obstacle

The nice part about working with no goal in mind
is that you can declare victory whenever it suits you.
Don't raise the bar: Hide it!
 
G

Gene Wirchenko

On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
[snip]
And how would you handle the aces?

A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
five-high straight).

In some "high-low" games, A-5-4-3-2 can be both a
five-high straight *and* an Ace with four low cards,
possibly winning both the "high" and "low" shares of
the pot.

Right. I have rarely ever played high-low and forgot about them.
Does anyone else have an exception to ambush us with? <g>

Sincerely,

Gene Wirchenko
 
G

Gene Wirchenko

Yes, start writing code
What do you suggest he does, Sit there twiddling his fingers.

I suggest that designing comes before writing code.
I bet you have a pre-meeting meeting to discuss what to discuss in the
meeting don't you. Ye gods and little Indians, I've battled with the

Straw man.

No, but I do work out what is needed in terms of features and
then work out the sorts of entities that I will need to implement
these.
likes of you all my professional life. I always deliver though because I
get code down and learn from it.

I write code, too, but the measure of a system is not just the
code. Its organisation counts for a lot.
Write code, make mistakes, refactor, reiterate ... LEARN

Or one can design and make far fewer mistakes.
Or sit on your hands lamenting your inability to get past the first obstacle

Another straw man.

Sincerely,

Gene Wirchenko
 
J

Joshua Cranmer

On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
[snip]
And how would you handle the aces?

A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
five-high straight).

In some "high-low" games, A-5-4-3-2 can be both a
five-high straight *and* an Ace with four low cards,
possibly winning both the "high" and "low" shares of
the pot.

Right. I have rarely ever played high-low and forgot about them.
Does anyone else have an exception to ambush us with? <g>

In the card game "capitalism," the highest card is a 2. ISTR a variant
where the highest card is a 3 as well....
 
M

markspace

Wow! Lots of great discussion going on here.

It's just the normal noises in here. We'll argue about anything really.
time. I've never done a card game before, so I will start with
something extremely minor, perhaps a Memory style game where you have

Don't forget that if you do make a standard deck, then nothing will
match. Unless you match on the values only, for example, and ignore suits.
 
G

Gene Wirchenko

On 18/12/12 16:07, Eric Sosman wrote:
On 12/18/2012 10:05 AM, lipska the kat wrote:
On 18/12/12 14:32, (e-mail address removed) wrote:
[snip]
Yes, start writing code
What do you suggest he does, Sit there twiddling his fingers.

I suggest that designing comes before writing code.

I agree ... but if you are suggesting that you do all the designing
before you start to write a line of code then I humbly suggest that that
approach is fundamentally and profoundly flawed.

No, but I do design code before I write it. The big design comes
first, then pieces of smaller design, then the code associated with
the smaller design. Repeat the last two steps as needed.
Just IME mind you, I'm sure you are not suggesting that.

Actually I suggest that they proceed in parallel.

For a given piece of code, design comes first.
Cheese sandwich

Entities, hmm, a word heavy with meaning to anyone who has ever written
EJBs. We deal in Classes, packages, components and Interfaces in Object
Oriented software engineering with Java, entities reflect persistence
schemata.

<Makes sweeping statement then withdraws to safe distance>

Or simply a word meaning something of interest. If code, it
might be a class or a procedure. It might also be who is using the
system, the hardware required, and so. It could also be things one
must consider such as privacy laws.
Well this depends on your approach to design doesn't it (see above)

Of course. How could it be otherwise?
Egg mayo on Rye, easy on the mayo

I forgotten how much fun the Usenet thing can be.

Maybe you should consider a conversation with colleagues a higher
priority than trolling.

Sincerely,

Gene Wirchenko
 
E

Eric Sosman

On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
[snip]

And how would you handle the aces?

A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
five-high straight).

In some "high-low" games, A-5-4-3-2 can be both a
five-high straight *and* an Ace with four low cards,
possibly winning both the "high" and "low" shares of
the pot.

Right. I have rarely ever played high-low and forgot about them.
Does anyone else have an exception to ambush us with? <g>

I think that sort of issue could be handled by having game-dependent
Comparator<Card,Card> implementations, rather than making Card Comparable.

A comparator might have a hard time declaring "Ace is lower
than Deuce" and "Ace is higher than Deuce" simultaneously ...

And then, there are games where two identical ranks in the
same hand can have different values. With A-A-9, for example, a
Blackjack player would get the desired total of 21 by counting
one Ace as a 1 and the other as an 11. (This appears to be the
class of game the O.P. is interested in.)
I would be more concerned about jokers, which do not follow the
(suit,value) pattern.

Other pattern-busters might be the Jacks of Spades and Hearts.
When "one-eyed Jacks are wild," they can be of any rank or suit.
(I've read that the King of Diamonds is sometimes considered wild,
but have never actually encountered the practice.)
 
E

Eric Sosman

On 18/12/12 16:07, Eric Sosman wrote:
On 12/18/2012 10:05 AM, lipska the kat wrote:
On 18/12/12 14:32, (e-mail address removed) wrote:
[snip]
Yes, start writing code
What do you suggest he does, Sit there twiddling his fingers.

I suggest that designing comes before writing code.

I agree ... but if you are suggesting that you do all the designing
before you start to write a line of code then I humbly suggest that that
approach is fundamentally and profoundly flawed.

Gene does not appear to take any such position, and I
most certainly do not. One need not (usually cannot) complete
all of the design ahead of time, because the implementation
process itself will produce surprises pleasant and unpleasant,
and these can be "learning opportunities." Knuth suggests the
learning can be so valuable that it can be a Good Thing to lose
all the code partway through development! (TAOCP section 1.4.1)

However, the fraction of design to be completed before
embarking on construction need not be an integer. When you
propose "all" as the only alternative to "none," you are being
silly. When you claim that people who disagree with you
subscribe to that false dichotomy, you are being an ass.
 
S

Stefan Ram

Eric Sosman said:
Gene does not appear to take any such position, and I
most certainly do not. One need not (usually cannot) complete
all of the design ahead of time, because the implementation
process itself will produce surprises pleasant and unpleasant,
http://mindhacks.com/2008/03/31/rock-climbing-hacks-now-with-added-speculation/
http://dilbert.com/blog/entry/visualizing_the_entire_path/

and these can be "learning opportunities." Knuth suggests the
learning can be so valuable that it can be a Good Thing to lose
all the code partway through development! (TAOCP section 1.4.1)

http://c2.com/cgi/wiki?PlanToThrowOneAway
 
G

Gene Wirchenko

On Tue, 18 Dec 2012 13:49:16 -0500, Eric Sosman

[snip]
Other pattern-busters might be the Jacks of Spades and Hearts.
When "one-eyed Jacks are wild," they can be of any rank or suit.
(I've read that the King of Diamonds is sometimes considered wild,
but have never actually encountered the practice.)

I used to play "Hooks, Crooks, One-Eyed Jacks, and the Man with
the Axe". Hooks are 2's; crooks are 7's. The man with the axe is the
king of diamonds.

Sincerely,

Gene Wirchenko
 
G

Gene Wirchenko

On Tue, 18 Dec 2012 17:39:02 +0000, lipska the kat
[snip]


No, but I do design code before I write it. The big design comes
first, then pieces of smaller design, then the code associated with
the smaller design. Repeat the last two steps as needed.
Just IME mind you, I'm sure you are not suggesting that.

Actually I suggest that they proceed in parallel.

For a given piece of code, design comes first.

Well if you call the mental process that we go through when we write a
piece of code 'design' then I agree but are you really saying that you
have never just written some code to test your thoughts BEFORE you
commit your thoughts to a formal model ... I find that hard to believe

Of course I have. My thoughts? They are the first part of the
design for that code.
[snip]
Maybe you should consider a conversation with colleagues a higher
priority than trolling.

Yes, this is an interesting point.
It's often appears to be the case that if someone doesn't agree with you
then they are trolling ... I often disagree with people but I don't call
them trolls.

I did not call you a troll. To be precise, you are leaning that
way.
Disappointing but sadly predictable.

And here I thought you were enjoying USENET. You did state "I
forgotten how much fun the Usenet thing can be." upthread.

Sincerely,

Gene Wirchenko
 
G

Gene Wirchenko

On 18/12/12 17:21, Gene Wirchenko wrote:
On Tue, 18 Dec 2012 16:27:28 +0000, lipska the kat

On 18/12/12 16:07, Eric Sosman wrote:
On 12/18/2012 10:05 AM, lipska the kat wrote:
On 18/12/12 14:32, (e-mail address removed) wrote:

[snip]

Yes, start writing code
What do you suggest he does, Sit there twiddling his fingers.

I suggest that designing comes before writing code.

I agree ... but if you are suggesting that you do all the designing
before you start to write a line of code then I humbly suggest that that
approach is fundamentally and profoundly flawed.

Gene does not appear to take any such position,

I'm sure 'Gene' can speak for himself.

I sure can, but what Eric wrote states my case wonderfully well.

[snip]

Sincerely,

Gene Wirchenko
 
A

Arne Vajhøj

And it will not.

Really, well thank you for pointing that out

[snip]
A Deck constructor with just the number of jokers would make
more sense to me.

Like I said, it was just an outline.

In my house we play games that use a subset of a complete deck,
sometimes we play a game that uses only the lower ranks of several packs
of cards

A Pack of cards contains 54 cards including two jokers.
a Deck of cards contains the cards required to play a game, not the same
thing at all ... hey look, we're already starting to come up with some
new classes, cool huh.

That would not be the definitions I would use.

But you could certainly define them that way.

Arne
 
A

Arne Vajhøj

These type of questions/issues would come out in the wash. You need a
place to start, often the final result looks nothing like the first
iteration. Object Oriented software engineering is an iterative process.
More that that it is a state of mind.

OO A/D/P should be independent of waterfall vs iterative.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top