Ok.. Here is what I would do.
'Place 'card' array definition here so it autoloads and is used by all subs that need it.
sub CreateDeck (Number)
redim Deck(52 * Number) 'Since we 'redim' Deck it is dynamic and we can resize it any way we want.
dim count, count2
for count = 0 to Number - 1
for count2 = 0 to 51
Deck(count) = count2
next
next
world.setvariable "Deck", join(Deck,",")
end sub
sub Shuffle (AName, Output, wilds)
dim TDeck
TDeck = split(world.getvariable ("Deck"), ",")
if wilds(1) = "new" then
if wilds(2) > 0 then
CreateDeck (wilds(2))
else
'This is for reshuffling the same deck. If you don't plan to
'allow a reshuffle 'during' play, then if can be romoved,
'since the intent is to replace any -1 entries with the proper
'cards.
CreateDeck (int((ubound(TDeck) + 1) / 52))
TDeck = split(world.getvariable ("Deck"), ",")
end if
end if
dim count, rn, Temp
randomize
'Add a world.send "Say ..." or the like here to indicate you are shuffling.
for count = 1 to wilds(1) 'Shuffle this many times.
for count2 = 0 to ubound(TDeck)
rn = int (ubound(TDeck) * Rnd) + 1
Temp = TDeck(rn) 'Gotta love VBScript... :P Would have been nice 'if' you could use
'Swap TDeck(rn), TDeck(count2), but they left out the command. Sigh...
TDeck(rn) = TDeck(count2)
TDeck(count2) = Temp
next
next
world.setvariable "Deck", join(TDeck,",")
world.setvariable "CardPos",0
end if
sub PullACard (AName, Output, Wilds)
Dim TDeck, CardPos
TDeck = split(world.getvariable ("Deck"), ",")
CardPos = world.getvariable ("CardPos")
'...
end sub
In PullACard you use CardPos to keep track of where in the deck you are. You can then increase it each time you 'pull' a card and even drop the value you get from TDeck into a hands. Keeping track of the hands is probably quite a bit more complex, since an array like Hand(player,cards), which would be easiest to define like Dim Hand(max players, max cards), is needed, but I am not sure how well you can join and split parts of an array (or if you can??). It should be possible though to adapt things to automatically fill hands for each player this way as well, etc. The above may turn out to be the easy part. lol
If you choose to allow something like reshuffling during the game, then I would suggest placing a -1 into any used card position in the deck, then just testing for it and skipping to the next card in the deck if it contains one after a reshuffle. The Shuffle sub is already set up to handle the existance of -1s in the array by regenerating the deck. The commands would be:
Yourshufflealias new - Resets the existing deck (in case of those nasty -1s and reshuffles it.
Yourshufflealias new # - Creates and shuffles a new deck with # 52 card decks in it.
Yourshufflealias - Shuffles the existing deck
You will also need to add a warning for when you start to drop below a certain number of cards left in the deck of course. ;)
As for the card names themselves. Just use the same array you are already, but place it with the before the rest and outside of the subs, that way it is automatically created and global to all routines. You then use the number from the randomized 'Deck' to retrieve the name.
NOTE: in modern versions of basic however, you have to specify if arrays will start with 1, if you do then all of them do and it is much easier to just remember to use 0. This means you should make your cards array 0 to 51, not 1 to 52. ;) Hope this helps. |