Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Design decision for a game

Reply
Thread Tools

Design decision for a game

 
 
andreas
Guest
Posts: n/a
 
      05-28-2008
Why you complicate so much a so simple problem ?
I think that you forgot analyze the problem before to proceed to
design decisions, my advice is to model whole game (rules, stacks of
cards etc) in a more abstracted way, e.g. forget about classes methods
and all stuff specific to the particular programming language and
attack the problem starting from its conceptual view, then apply any
analysis technique you, divide and conquer or a la guerrilla warfare
way. Anyways the objective is to make a crystal clear picture of your
problem.

My personal opinion is that most of card games can be modeled as
states e.g. any combination of cards in various lists of cards (e.g.
stack, closed, open etc) representing a particular state, the state
may be valid or invalid one (this is where rules apply), in other
words imagine rules as a function that has as it's domain any possible
state of the game and the range true|false; this function validates if
cards are in correct place.

By applying the validation function on every change of the state (for
example card put in specific stack) you can keep rules of the game in
order.

If you want to validate the state partially (maybe for speed reasons)
you can brake up the domain in smaller parts and for each part apply
function validating the part, again by applying validation piecewise
all outcomes should be true in order to ensure the validity of whole
game.

Now let's see possible design in Java that will implement all the
above. Abstractly. You have two parts (where each part may consist of
many objects) :

1. The state
2. The Rules

Let's suppose we have a class Rules providing a method

bool validate(State)

each time the state changes you give it to the validate() method and
get a result if everything is ok or awry.
If rules are correct and the State represents the domain clearly and
correctly you have a bulletproof game.

If you want to complicate things more you can apply more complex
validation techniques (consult GoF book ) but it seems there is no
reason to complicate them in such problem.
 
Reply With Quote
 
 
 
 
pek
Guest
Posts: n/a
 
      05-28-2008
On May 28, 10:54 am, andreas <(E-Mail Removed)> wrote:
> Why you complicate so much a so simple problem ?
> I think that you forgot analyze the problem before to proceed to
> design decisions, my advice is to model whole game (rules, stacks of
> cards etc) in a more abstracted way, e.g. forget about classes methods
> and all stuff specific to the particular programming language and
> attack the problem starting from its conceptual view, then apply any
> analysis technique you, divide and conquer or a la guerrilla warfare
> way. Anyways the objective is to make a crystal clear picture of your
> problem.
>
> My personal opinion is that most of card games can be modeled as
> states e.g. any combination of cards in various lists of cards (e.g.
> stack, closed, open etc) representing a particular state, the state
> may be valid or invalid one (this is where rules apply), in other
> words imagine rules as a function that has as it's domain any possible
> state of the game and the range true|false; this function validates if
> cards are in correct place.
>
> By applying the validation function on every change of the state (for
> example card put in specific stack) you can keep rules of the game in
> order.
>
> If you want to validate the state partially (maybe for speed reasons)
> you can brake up the domain in smaller parts and for each part apply
> function validating the part, again by applying validation piecewise
> all outcomes should be true in order to ensure the validity of whole
> game.
>
> Now let's see possible design in Java that will implement all the
> above. Abstractly. You have two parts (where each part may consist of
> many objects) :
>
> 1. The state
> 2. The Rules
>
> Let's suppose we have a class Rules providing a method
>
> bool validate(State)
>
> each time the state changes you give it to the validate() method and
> get a result if everything is ok or awry.
> If rules are correct and the State represents the domain clearly and
> correctly you have a bulletproof game.
>
> If you want to complicate things more you can apply more complex
> validation techniques (consult GoF book ) but it seems there is no
> reason to complicate them in such problem.


So, if I understood correctly, you are saying that House should add
the card anyway, and then run all the rules. Each rule will examine
the state of the house as it thinks and return true (if the state is
ok or the rule doesn't make sense) or false (if the state is erroneous
according to the rule).

Is this correct? If yes, that means that the House will add the card
first and then run the rules. If any rules reports an erroneous state,
what will the house do? Will it remove the card and throw an exception?
 
Reply With Quote
 
 
 
 
pek
Guest
Posts: n/a
 
      05-29-2008
On May 29, 12:53 am, pek <(E-Mail Removed)> wrote:
> On May 28, 10:54 am, andreas <(E-Mail Removed)> wrote:
>
>
>
> > Why you complicate so much a so simple problem ?
> > I think that you forgot analyze the problem before to proceed to
> > design decisions, my advice is to model whole game (rules, stacks of
> > cards etc) in a more abstracted way, e.g. forget about classes methods
> > and all stuff specific to the particular programming language and
> > attack the problem starting from its conceptual view, then apply any
> > analysis technique you, divide and conquer or a la guerrilla warfare
> > way. Anyways the objective is to make a crystal clear picture of your
> > problem.

>
> > My personal opinion is that most of card games can be modeled as
> > states e.g. any combination of cards in various lists of cards (e.g.
> > stack, closed, open etc) representing a particular state, the state
> > may be valid or invalid one (this is where rules apply), in other
> > words imagine rules as a function that has as it's domain any possible
> > state of the game and the range true|false; this function validates if
> > cards are in correct place.

>
> > By applying the validation function on every change of the state (for
> > example card put in specific stack) you can keep rules of the game in
> > order.

>
> > If you want to validate the state partially (maybe for speed reasons)
> > you can brake up the domain in smaller parts and for each part apply
> > function validating the part, again by applying validation piecewise
> > all outcomes should be true in order to ensure the validity of whole
> > game.

>
> > Now let's see possible design in Java that will implement all the
> > above. Abstractly. You have two parts (where each part may consist of
> > many objects) :

>
> > 1. The state
> > 2. The Rules

>
> > Let's suppose we have a class Rules providing a method

>
> > bool validate(State)

>
> > each time the state changes you give it to the validate() method and
> > get a result if everything is ok or awry.
> > If rules are correct and the State represents the domain clearly and
> > correctly you have a bulletproof game.

>
> > If you want to complicate things more you can apply more complex
> > validation techniques (consult GoF book ) but it seems there is no
> > reason to complicate them in such problem.

>
> So, if I understood correctly, you are saying that House should add
> the card anyway, and then run all the rules. Each rule will examine
> the state of the house as it thinks and return true (if the state is
> ok or the rule doesn't make sense) or false (if the state is erroneous
> according to the rule).
>
> Is this correct? If yes, that means that the House will add the card
> first and then run the rules. If any rules reports an erroneous state,
> what will the house do? Will it remove the card and throw an exception?


In case anyone is wondering, I finished the game and uploaded it to my
site. It's at http://treazy.com/apps/javacorner. The game is called
House of Cards.

Again, thank you for all your advises. I couldn't have done it without
you.
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      05-29-2008
On Wed, 28 May 2008, andreas wrote:

> Why you complicate so much a so simple problem ?
>
> [snip]


Andreas, your suggestion is not only every bit as complicated as the
solution Pek chose, it doesn't actually solve the problems his did!

tom

--
It's almost over now.
 
Reply With Quote
 
pek
Guest
Posts: n/a
 
      06-03-2008
On May 29, 6:11 pm, Tom Anderson <(E-Mail Removed)> wrote:
> On Wed, 28 May 2008, andreas wrote:
> > Why you complicate so much a so simple problem ?

>
> > [snip]

>
> Andreas, your suggestion is not only every bit as complicated as the
> solution Pek chose, it doesn't actually solve the problems his did!
>
> tom
>
> --
> It's almost over now.


One more thing before this discussion dies..
Remember the Joker rule? If a joker enters a house with a different
suit, the game is over, otherwise the cards in a house clear and the
player gains points (in this game, jokers have suit). A house of cards
can also close if the sum of card points in it exceeds 31 (each cards
has a number of points). The player wins if he uses all 56 cards in
the deck without losing. If you think about it, if a House closes and
the joker with the same suit is still in the deck, eventually the
player will lose. So it is pointless.

Currently my system goes like this:
The house has a list of rules which every time a card is going to be
added, it runs them and gets the results (whether the card can enter,
it reached 31 etc.). When a player wants to add a card to the house,
he clicks a component in the GUI. The GUI then calls the engine to add
the card in a house and the engine simply calls the corresponding
house to add the card. In other words, the Engine (although it
contains all the game logic - starts new games, checks for game over
etc.) it doesn't care about entering a card in the house since the
house has this functionality.

Now, determining whether the deck contains a joker of a certain suit
cannot be done in this system simply because the house isn't aware of
such things as other houses or decks. The solution I can think is
passing the rules responsibility to the Engine and leaving the House
to be simply a data type. So then the Engine can check other houses
etc.

What do you think about this? Any comments/suggestions..?
 
Reply With Quote
 
pek
Guest
Posts: n/a
 
      06-09-2008
On Jun 3, 9:20 pm, "Peter Duniho" <(E-Mail Removed)>
wrote:
> On Tue, 03 Jun 2008 03:54:21 -0700, pek <(E-Mail Removed)> wrote:
> > [...]
> > Now, determining whether the deck contains a joker of a certain suit
> > cannot be done in this system simply because the house isn't aware of
> > such things as other houses or decks. The solution I can think is
> > passing the rules responsibility to the Engine and leaving the House
> > to be simply a data type. So then the Engine can check other houses
> > etc.

>
> > What do you think about this? Any comments/suggestions..?

>
> I'm not exactly clear on what "rules responsibility" means. Just because
> a Rule has subscribed to a House's event, I don't see how that means that
> the House is _responsible_ for the Rule per se.
>
> But yes, it seems to me that Rules are not a House-level construct, but
> rather a whole game- (Engine-) level construct, and as such would have
> access to all House instances, through the Engine. I would, in fact,
> expect that the Engine is the class that's actually managing the Rule
> instances, even as each Rule instance may have subscribed to multiple
> House instances to receive events that affect game state, etc.
>
> Pete


Yes, that where my thoughts exactly. Thanks for your feedback..
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Twisted Design Decision koranthala Python 0 01-27-2009 01:46 PM
Class design decision __PPS__ C++ 5 12-08-2006 09:39 AM
Feedback on a design decision? Jeff Marder Java 15 10-09-2006 02:26 PM
Help with design decision tubby ASP .Net 1 12-04-2005 01:45 PM
[JSP] Help with Design decision Marcus Reiter Java 1 12-30-2004 01:36 PM



Advertisments