Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Eiffel > Re: Proper way
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 881 of 917
Post > Topic >>

Re: Proper way

by Colin Paul Adams <colin@[EMAIL PROTECTED] > Aug 31, 2007 at 12:08 PM

>>>>> "Tobias" == iso8859-1  <iso8859-1@[EMAIL PROTECTED]
> writes:

    Tobias> I managed to create some kind of die that uses the
    Tobias> procedure roll to roll a die and then a query d(side :
    Tobias> Integer) to get the result interpreted as an appropriate
    Tobias> die.

    Tobias> But how do I design the dice roller for these complexer
    Tobias> expressions?  In Java I would just do something like
    Tobias> roll(count, side, offset : Integer) : Integer but that
    Tobias> would change the internal state of the object. How do I
    Tobias> seperate the queries from the commands cleanly in this
    Tobias> case? Could someone give me an idea?

The usual way is for roll to set an attribute (say last_roll: INTEGER)
to the value produced. Then you call `roll' and follow by accessing the
value of `last_roll'.
If you need to access this object from multiple threads, then you need
to synchronize round the two calls. An alternative design for this
scenario is to pass a reference argument to receive the result.

Note that I wouldn't make `side' an argument of `roll'. rather I would
make it an attribute of the class. You set it in the creation
procedure, and have a different object for a 6-sided die, and a
20-sided die.  

Although I wouldn't really want to transfer the 3d6, 1d100 examples
directly from an rpg to my program. Instead I would go for the
abstract of a random number distribution, and sample that directly
(you might name the distribution objects with names such as 3d6
though, within an rpg).
-- 
Colin Adams
Preston Lancashire




 3 Posts in Topic:
Proper way
iso8859-1@[EMAIL PROTECTE  2007-08-29 13:01:39 
Re: Proper way
Colin Paul Adams <coli  2007-08-31 12:08:07 
Re: Proper way
iso8859-1@[EMAIL PROTECTE  2007-09-02 23:00:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 7:16:05 CDT 2008.