On Sat, 19 Jul 2008 18:50:56 -0400
"Rod Pemberton" <do_not_have@[EMAIL PROTECTED]
> wrote:
> Now, the
> internal representation of the deck of cards used by a computer
> program isn't random at all but is sequentially ordered:
> 1,2,3,4, ...,51,52.
In some cases, yes. Often the deck is shuffled, and the cards are
sequentially dealt out to the various hands. In the specific case of
"gnome-hearts", which is the game engine for which I wrote my AI
player, The deck does remains in order, but the cards are drawn
randomly from the deck. At no time does the game engine ever have a
representation of a random deck order.
> Well, it possibly does
> so by a conversion function and an specific input to that function.
Such a function is useful for creating the initial (shuffled) state of
the deck, so that a player may note the number of the hand and replay
it at some future time. However, if this technique is used, there is no
need for the game engine to also have a sequentially ordered deck
representation.
> This is only useful if functions to do
> the opposite also exist.
In the context we have been discussing, such a reverse function is not
necessary, since tracking the specific order of the cards is only of
use at the time when the cards are dealt. Once the cards are moved from
the deck to a player's hand, it no longer matters in which order they
were received.
> So, is there a value that can represent of each of
> these orders? Is there a function to generate each of these orders
> given that value?
Yes, and probably an infinite number of them, at that. Let's start with
a couple of existence proofs.
It is axiomatic that all possible permutations of 52 cards, no matter
how ordered, can be held in an array with 52 columns and 52! rows. To
convert a row number into an array pointer, one merely multiplies the
row number by 52 and adds the result to the address of the start of the
array. In the worst performing case, the reverse function can search
the rows for a match. Beyond this, everything else is just optimization.
If we use a function generator, then we can do away with the actual
array, and just create a single row, as needed. In the worst
performing case, the function generator can do this by simply stepping
through the algorithm, and throwing away the result until it gets to
the desired row. Likewise, the reverse function can be performed by
stepping through the algorithm and comparing the result to the target
row. Again, everything else is just optimization.
Or, we could represent each of the 52 cards as a single digit in a base
52 number system, and each permutation as a 52 digit number in that
base.
"But the task of filling out the list I'd rather leave to you." [From
'The Mikado', by Gilbert & Sullivan.]
--
Chuck
http://www.pacificsites.com/~ccrayne/charles.html


|