[messages] [Module Design] Re: Random Selection

JustaBill martinson2005 at netscape.net
Thu Jan 26 21:16:43 MST 2012

"mycenae" wrote:
> More complex: create 1 empty deck for each player that is set to
> random shuffle (call it a shuffle deck). Put a Return to Deck (RTD)
> trait on each card that returns the card to each player's private
> shuffle deck, and another RTD that moves the card to the discard pile.
> To each shuffle deck, add a Deck GKC that will apply the Discard RTD
> command to 1 card. 
> When it's time to discard a random card, use the first RTD to move all
> the cards to each player's shuffle deck. (You could set up a Global
> Key Command button to do this for everyone at once.). Then right-click
> on each shuffle deck and trigger the Deck GKC...this will have the
> effect of moving 1 random card from the shuffle deck to the discard
> pile. Players can now retrieve the remaining cards from their shuffle
> deck and play resumes.

Clever.  It appears that this may be the only way (without custom
classes) to perform true automated randomness without the player having
to supply a count value to a variable-sided die or manually count off

I like your idea, but it has a few drawbacks: (1) Moving the cards back
and forth could be disruptive if the player has arranged his cards in a
certain way in his hand. (2) The cards to be randomly selected from
might not all be in the same hand. (3) The intended result of the random
selection might be something other than discarding the selected card.
(4) The resulting number of cards to be randomly selected might be more
than 1.

All of these things are true in the Cosmic Encounter module I'm
developing.  So I extended your idea to accomplish the following:
  1. Player selects one or more cards (anywhere in play; need not all be
in the same hand, stack, whatever).
  2. Player clicks a Random Selection toolbar button: One of the
selected cards is randomly indicated by activating or incrementing a
Layer property.
  3. Player clicks a Select Another toolbar button: Another (different)
card in the selection group is highlighted by setting its Layer.  4.
Player clicks a Clear All Random Selection buttons: all highlight layers
are turned off.
  5. None of the selected cards are moved around or modified in any way
except to set/clear the random-selection highlight layer.

There are too many details to cover here, and my prototypes are pretty
complex (lots more stuff than just this), but I'll describe the basic
approach.  The idea is to use your trick of sending pieces to a deck
that's set to always randomize, but instead of sending the _actual_
cards I send something else in their place: a "delegate" that I create
on the fly.  A link is created from the delegate to the Card, all the
delegates are sent to the always-random Delegate Pool deck, and one
delegate is drawn from that deck.  The act of drawing the delegate tells
the delegate to tell its linked card to set its own highlight layer. 
The other delegates not chosen remain in the Delegate Pool so the user
can click Select Another and get a second, third, etc. selection from
among the remaining candidates. The delegates and their deck are off in
another window that the players never really see.

Linking the delegate to the card is a little tricky.  I know each object
has its own unique ID, but the documentation doesn't tell us if this is
exposed to the designer; so I rolled my own.  I have a global property
called UniqueID that goes from 0 to 100000 with rollover.  Each time a
card is triggered for the selection process, it increments the global
property (to produce a new unique ID), copies the UniqueID to its own
DelegateID property, then does a Place Marker to create the delegate,
passing a keystroke to the delegate.  That keystroke makes the delegate
copy down the UniqueID to its own CardID property (establishing the link
between delegate and real card), then send itself to the Delegate Pool

When the delegate is drawn, it sends a global key command to all pieces
with DelegateID = $CardID$ ... meaning the _one_ card that uniquely
matches the delegate.  Thus that card (alone) highlights itself.

The toolbar button that draws a delegate is used by the main
Multi-Action Button that performs the overall process, but it can also
be clicked independently to get 'Another' selection from the same pool,
since all it does is draw another delegate from the random Delegate Pool

For cleanup, when the main Multi-Action Button is clicked to start a
brand-new random selection, the first thing it does is issue a Global
Key Command to tell all delegates everywhere to delete themselves. 
Thus, the delegates that get spawned from all the currently selected
cards will be the only candidates in the Delegate Pool deck.

Sorry this isn't more precisely written; if only I had more time.  It's
working perfectly in my module, so if any reader can't get this to work
it is the fault of my rushed general notes and not a limitation of

Read this topic online here:

More information about the messages mailing list