 |
|
 |
|
 |
04-19-2009, 03:37 AM
|
#1 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Shuffling Cards.
I cannot figure out how to do it efficiently.
Please someone help.
|
|
|
04-19-2009, 05:17 AM
|
#2 (permalink)
|
|
Registered Member
Join Date: Aug 2008
Posts: 398
|
I find the best way is to place them all face down on a table and then do multiple circle movements over the top of them. (kind of a wax on, wax off motion).
|
|
|
04-19-2009, 10:36 AM
|
#3 (permalink)
|
|
Pro. Game Developer
iPhone Dev SDK Supporter
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 1,426
|
Quote:
Originally Posted by Stitch
I find the best way is to place them all face down on a table and then do multiple circle movements over the top of them. (kind of a wax on, wax off motion).
|
Oh, snap.
|
|
|
04-19-2009, 11:45 AM
|
#4 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Quote:
|
I find the best way is to place them all face down on a table and then do multiple circle movements over the top of them. (kind of a wax on, wax off motion).
|
Seriously dude I really need help with it.
|
|
|
04-19-2009, 11:53 AM
|
#5 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 48
|
Then maybe you should try being more specific about your problem. The guy above me answered your question, if that's not what you meant, then clarify...
You could also try bridging the cards, thats always fun to do.
|
|
|
04-19-2009, 12:01 PM
|
#6 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Quote:
Originally Posted by XenoSage
Then maybe you should try being more specific about your problem. The guy above me answered your question, if that's not what you meant, then clarify...
You could also try bridging the cards, thats always fun to do.
|
Okay. I have 52 images of all the cards, I want to have an array of these images and then all of the indexes get reasigned randomly (there in order when you start.) But ive tried this before and I couldnt get it to work.
|
|
|
04-19-2009, 12:05 PM
|
#7 (permalink)
|
|
Registered Member
Join Date: Nov 2008
Posts: 788
|
Quote:
Originally Posted by iphonedev.
Okay. I have 52 images of all the cards, I want to have an array of these images and then all of the indexes get reasigned randomly (there in order when you start.) But ive tried this before and I couldnt get it to work.
|
What couldn't you get to work? rand()?
|
|
|
04-19-2009, 12:08 PM
|
#8 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 48
|
next thing you want to do is post your code as is right now so we don't suggest what you already have.
|
|
|
04-19-2009, 12:11 PM
|
#9 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Quote:
Originally Posted by johnqh
What couldn't you get to work? rand()?
|
Well it kept repeating numbers and I could not get them to change indexes within the array. Like card 1 is at index 0 and after shuffling card 1 is at index 25.
|
|
|
04-19-2009, 12:17 PM
|
#10 (permalink)
|
|
Registered Member
Join Date: Nov 2008
Posts: 788
|
Quote:
Originally Posted by iphonedev.
Well it kept repeating numbers and I could not get them to change indexes within the array. Like card 1 is at index 0 and after shuffling card 1 is at index 25.
|
We still don't know how you are shuffling them.
|
|
|
04-19-2009, 12:20 PM
|
#11 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 48
|
I would suggest doing something more along the lines of not actually changing the index positions of the cards. Instead, use a random number generator and an if check to make sure you havent accessed that position already to retrieve cards from the deck at random.
If this were in java i'd say just use Collections.shuffle(), but i don't know the NSMutableArray equivalent if there is one.
|
|
|
04-19-2009, 12:23 PM
|
#12 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Code:
for (int j = 0; j < numberArray.count; j++) {
int randomIndex = (arc4random() % 52);
[cardsArray exchangeObjectAtIndex:j withObjectAtIndex:randomIndex];
}
Thats what I am using to shuffle the cards but it says "cardsArray may not respond to exchangeObjectAtIndex"
|
|
|
04-19-2009, 12:26 PM
|
#13 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 48
|
are you using NSMutableArray and not NSArray?
|
|
|
04-19-2009, 12:27 PM
|
#14 (permalink)
|
|
Magic Hands' Daddy
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 22
Posts: 1,372
|
@OP:
You should really learn to use Google to your benefit. A simple search for "objc shuffle nsarray" provided exactly what you're looking for.
Even though you may not want to use the code directly, you can at least use it as a learning tool.
|
|
|
04-19-2009, 12:31 PM
|
#15 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Quote:
Originally Posted by XenoSage
are you using NSMutableArray and not NSArray?
|
Usinag a NSArray. Should I be using NSMutableArray.
|
|
|
04-19-2009, 12:33 PM
|
#16 (permalink)
|
|
Magic Hands' Daddy
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 22
Posts: 1,372
|
Yea
|
|
|
04-19-2009, 12:33 PM
|
#17 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 48
|
Yes, for that method to work, you need an NSMutableArray.
Mutable literally means (you can edit it!)
|
|
|
04-19-2009, 12:40 PM
|
#18 (permalink)
|
|
Magic Hands' Daddy
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 22
Posts: 1,372
|
Give to a bunch of developers for making object type literally describe what they do :-)
|
|
|
04-19-2009, 12:52 PM
|
#19 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 48
|
I know right?!?!
|
|
|
04-19-2009, 12:58 PM
|
#20 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Quote:
Originally Posted by XenoSage
Yes, for that method to work, you need an NSMutableArray.
Mutable literally means (you can edit it!)
|
Thanks lol
Also how do I put my UIImageViews into an array.
|
|
|
04-19-2009, 01:34 PM
|
#21 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 48
|
what are you doing right now that isnt working?
|
|
|
04-20-2009, 01:24 AM
|
#22 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 92
|
Quote:
Originally Posted by XenoSage
what are you doing right now that isnt working?
|
Roght now I got all the cards to shuffle using NSNumbers that start out 1-52 then there indexes change like the code i posted before. Based on those indexes I can set the images to the corresponding index for the user to see them. Now I am stuck as how to do one thing, I am making blackjack so I need to see if the cards are geater than 21 added up, so that means that (since the cards are label 1-52) it will not always add up to want. Say Number 1 is Jack of spades, and Number 10 is Ace of Spades. Those do not add up to 21, they add up to 11, so how do I reassign these values so that Jack of Spades is 10 and Ace of Spades is eleven, etc.
Sorry if that was confusing lol
|
|
|
04-20-2009, 01:41 AM
|
#23 (permalink)
|
|
Registered Member
Join Date: Nov 2008
Posts: 192
|
Quote:
Originally Posted by iphonedev.
Roght now I got all the cards to shuffle using NSNumbers that start out 1-52 then there indexes change like the code i posted before. Based on those indexes I can set the images to the corresponding index for the user to see them. Now I am stuck as how to do one thing, I am making blackjack so I need to see if the cards are geater than 21 added up, so that means that (since the cards are label 1-52) it will not always add up to want. Say Number 1 is Jack of spades, and Number 10 is Ace of Spades. Those do not add up to 21, they add up to 11, so how do I reassign these values so that Jack of Spades is 10 and Ace of Spades is eleven, etc.
Sorry if that was confusing lol
|
Instead of shuffling the images... you should shuffle the "idea" of a card. I guess you could create a Card class.
On a side note, is there not already a blackjack app available? If there is, there's no rush... and I would learn the programming fundamentals properly. It will only help you in the long run.
|
|
|
04-20-2009, 02:14 AM
|
#24 (permalink)
|
|
Registered Member
Join Date: Aug 2008
Posts: 398
|
What have you stored in cardsArray?
I would probably place a NSDictionary something like:
Code:
[cardsArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithString:@"Diamond"], @"suitKey",
[NSString stringWithString:@"Jack"], @"cardKey",
[NSNumber numberWithInt:10], @"valueKey",
nil]];
This way you can easily find the Suit, Card Number and value at a specific index point in cardsArray.
Code:
int cardValue = [[[cardsArray objectAtIndex:25] objectForKey:@"valueKey"] intValue];
|
|
|
04-20-2009, 09:16 AM
|
#25 (permalink)
|
|
Registered Member
Join Date: Nov 2008
Posts: 192
|
Probably a good idea to extract that into a struct or class.
|
|
|
 |
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 352 |
| 29 members and 323 guests |
| AptoTech, asiago, bensj, byDecker, chouchou, djp_phillips, Duncan C, eieiosoftware, Falcon80, Forsworn, funkyspider, gbaldwin9, geoffrain, germainesluaus, gpacheco, Guit, harry123456, HemiMG, iGeorG, irish_kiwi, iSdkDev, johnlikesit, kwanwoolee, MartinIngvar, meeper, miguel.campiao, NewiPhoneDeveloper, whale88, zhz |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,288
Threads: 39,077
Posts: 171,356
Top Poster: smasher (2,575)
|
| Welcome to our newest member, germainesluaus |
|