Once the cards are delt out and there are cards stil on the table. How do you shuffle the cards actauly the shuffling part i have got,i need to take the cardsDelt out of the cards array.
//pop's down to zero cards left from 53 full deck of cards
cards = new array();
//push card names into cards array
cards = push("2d","3d","4d","5d","6d","7d","8d","9d","10d" ,"Jd","Qd","Kd","Joker","2s","3s");
//cards left on the table dont need to be in the next shuffle
//the cards in cards delt this will vary could be ("6h","10s");
cardsDelt= new Array("5d","Joker","Qd");
trace(cards);
If i have two arrays how can i take the strings out of the first.
As you know its a deal of cards so it's fairly obviously. I bothered to explain it if you had of read it, how mutch better can i put it? Its a deck of cards being reshuffled but the card existing on the table (or screen) dont get reshuffled.
I need to take these values out of the cards array but these values are always going to change. The cards game im biulding is Pontoon or some people know it as 21's. this is a small example the real array have 53 cards in it including the Joker.
cardsDelt= new Array("5d","3d","6d");
cards = new Array("2d","3d","4d","5d","6d","7d");
I shift the first number of the array and attach that from the libary onto a mc. Once there is no cards left in the array. I push the 53 card names back into the array.
In this example what should be left in the cards array is this.
cards = new Array("2d","4d","7d");
Then i do the reshuffle on whats left so its a random again , i know how to do the random reshuffle but not the taking values out of the cards array!!
2d is for 2 dimaonds , 3d for 3 diamonds ect. Youknow what i mean now??
You may think you're explaining your problem, but it's still clear as mud, and not helped by irrelevant code samples.
Anyway, through translation, I presume what you are asking is when you pick a 'card' from your array, how do you take that 'card' out of the array before it gets reshuffled.
And the answer - use [i]array[i].splice(), where [i]array[i] represents the name of your array. Have a look at this for more info:
Could anyone give me a real code example of how they would take these ,'group' of values out of the array?
I already read up on splice because i thought that was around the way to do it. But i could not understand how to write the code. Thats's why i asked the question.
//using this example
cardsDelt= new Array("5d","3d","6d");
cards = new Array("2d","3d","4d","5d","6d","7d");
How are you deciding which cards are dealt? Are you just making a new array with random cards in it, or are you picking cards from their positions in the main deck?
Here's how I would work it:
The mainDeck array has 54 cards (two jokers, isn't it?) - that's 54 array elements. If I need to pull two of them, I would get the first by selecting a random number between 0 and 53, use the card in that array slot, and splice the card out. To get the second card I would do the same again - get a random number between 0 and 52 (remember there are only 53 cards in the deck now), use the card refered to in that slot, then splice the card out.
The code might look something like this (placed in the first frame of the _root timeline):
Code:
mainDeck = new Array([all cards placed in here]);
// ----- make a function to get cards -----
getCards = function (quantity) {
// ----- make a new array to contain the picked cards -----
chosenCards = new Array()
// ----- make a loop that runs for as many cards as are required -----
for (i = 0; i < quantity; i++) {
// ----- select a random 'slot' -----
slot = Math.floor(Math.random() * _root.mainDeck.length);
// ----- insert the name of the card in that slot into the new array -----
chosenCards[i] = _root.mainDeck[slot];
// ----- delete the card from the mainDeck using .splice -----
_root.mainDeck.splice(slot, 1);
}
// ----- return the chosenCards array -----
return chosenCards;
};
In order to use getCards(), you would create a button with this code:
Code:
_root.newCards = _root.getCards(2);
That would return an array containing 2 cards selected then deleted from the mainDeck.
Is this any help?
----------
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." TERRY PRATCHETT
Piont taken i think thier is two jokers in a deck. I havent looked right into the proper ruling for the game Pontoon. We play it with one joker because we think its unfair to have two. Some people play it with two. Anyway that doesnt matter its the theory on taking the values out of the array to get the functionality right now.
Looked at your fla Coffee wish i could be as advanced as that. Amazing how dif people take differant approaches. Can i attach the fla i have most of the shuffling funtioning down its just the reshuffle because if there is existing cards already deal on the sceen if there is a reshuffle of a hole deck the cards left on the table need to be out of the new deck reshuffle, before new cards can be delt out again.
It's in development i commented the problem part probably easier to see it.
Hey youknow your Pontoon. Changed that bit. (l'l take your word for it that thats what it needed)
When i looked at the fla it would only go to three cards on first go and i thought ohh he's stuffed it up. Then i looked down and seen the trace BUST!! . Owesome you concored the next very puzzling question befor i had a chance to asked it.
Thats alot in place now, think now its going to get complicated.
Thanks for you help garbage sorry l'm a bit hard to understand.
Thanks for help Coffeee.
Glad to help. By the way, there is a bit of a bug in the removeCards function - if the card isn't found, it deletes the last card. This should never happen, but in case it does use the fixed function below instead. Also, the earlier modification was unnecessary and could cause problems. So I took it out.
PHP Code:
packOfCards.prototype.removeCards = function(arrayOfCards) {
for (var i = 0; i<arrayOfCards.length; i++) {
var found = search_array(arrayOfCards[i], this.cards);
if (found) {
this.cards.splice(found, 1);
}
}
};
Sorry to question in such an old thread, but I'm having a VERY similar problem, and I've almost got it figured out if only I could find a way to "refresh" the Array.
Here's how I have it layed out so far (I've changed some names, but the code is basically the same)
code:
delArray = new Array();
undelArray = new Array();
removeID = function(removeArray) {
for (var i=0; i < removeArray.length; i++) {
delArray.splice(search_array(removeArray[i], delArray), 1);
removeArray.splice(i,1);
}
};
// SEARCH FUNCTION FOR ARRAY
search_array = function(searchterm, _array) {
// Returns -1 if searchterm not found or the first matching index in searcharray.
var found = -1;
for (var i = 0; i<_array.length && found == -1; i++) {
if (searchterm == _array[i]) {
found = i;
}
}
return found;
};
So basically what I'm trying to do is to toggle between deleting the message (like hotmail does to delete multiple messages) so when the user clicks the button the messageID is added to the "delArray" which is all fine and well, but when they uncheck the box, I send the messageID into the "undelArray" and use the search function to find the ID in the undelArray to remove it from the delArray.
The problem comes when I don't have the option to "refresh" the array after it's finished. I can check a whole lot and they will add, and then when I uncheck a whole lot nothing happens, BUT, then if I check a box after unchecking a lot, the array "refreshes" only showing the boxes that are checked.
I've been working on this for SOO long, and it feels so good to be so close.
Any help would be amazing!
Thanks!
edit: I've used the Array.toString function to pull what I need. My god it feels SOOO good to be able to get on with this little project!
Thanks for those functions, they are a godsend!
Last edited by Endoplasmic; 10-03-2003 at 01:23 AM.