ID:266293
 
how would i make a proc that would take a stack of objects and shuffle them?
What the heck do you mean "shuffle them"?
Generally, you can get a randomized result by using rand(), pick(), etc. If you are trying to simulate cards, I suggest you just assign them to a list, use pick to select them (when drawn or whatever), the move the "card" out of the list.

-James
In response to Jmurph
Jmurph wrote:
What the heck do you mean "shuffle them"?
Generally, you can get a randomized result by using rand(), pick(), etc. If you are trying to simulate cards, I suggest you just assign them to a list, use pick to select them (when drawn or whatever), the move the "card" out of the list.

-James

Mix them up.
In response to Air _King
Um, well, if you follow Jmurph's advice, you'll find that is probably what you need. No need to mix up the list of cards, just have the pick() select a card at random. Then remove that card from the list so it won't be picked agian. Pretty straightforward if you ask me....

~X
In response to Xooxer
Xooxer wrote:
Um, well, if you follow Jmurph's advice, you'll find that is probably what you need. No need to mix up the list of cards, just have the pick() select a card at random. Then remove that card from the list so it won't be picked agian. Pretty straightforward if you ask me....

~X

then i would have to pick what cards would be in the list, but I want the cards in the list to be randomly generated. Oh Well.
Air _King wrote:
how would i make a proc that would take a stack of objects and shuffle them?
proc/Shuffle(list/cards)
var/card
for(var/i=cards.len,i>1,--i)
var/j=rand(1,i)
card=cards[j]
cards.Cut(j,j+1)
cards+=card

That ought to do the trick.

Lummox JR
In response to Air _King
That would be a seperate operation alltogether. I assumed that you had a set deck, like in Una, or Spades, or whatever...

But if you are using dynamic decks (like in Magic, etc...) Then you'll need to make a proc to add the individual cards to the list. I suppose you could make another list for this proc to pick from, and simply re-use the first proc to do both things, create the deck, and randomly give out cards from that deck...

It all depends on how your game is going to behave. I was simply pointing out that the advice given to you previously was valid, and should (with perhaps slight alterations) do what you need it to.

~X
In response to Xooxer
Xooxer wrote:
That would be a seperate operation alltogether. I assumed that you had a set deck, like in Una, or Spades, or whatever...

But if you are using dynamic decks (like in Magic, etc...) Then you'll need to make a proc to add the individual cards to the list. I suppose you could make another list for this proc to pick from, and simply re-use the first proc to do both things, create the deck, and randomly give out cards from that deck...

It all depends on how your game is going to behave. I was simply pointing out that the advice given to you previously was valid, and should (with perhaps slight alterations) do what you need it to.

~X

So like under
obj
card
monster
New()
list+=monster

is that the idea?
In response to Air _King
then i would have to pick what cards would be in the list, but I want the cards in the list to be randomly generated. Oh Well.

The list would represent the deck. For normal playing cards, the deck isn't random--the same 54 cards are always in there. See LummoxJR's example in this thread.

On the other hand, if you're trying to do a CCG, you just build a random deck out of master lists of common/uncommon/rare cards.