Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help Making A Deck Of Cards
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Psychotogen




PostPosted: Tue Apr 22, 2008 11:14 am   Post subject: Help Making A Deck Of Cards

Could anyone help me make a deck of cards in an arrary or something, i'm somewhat familiar with turing.
Sponsor
Sponsor
Sponsor
sponsor
Tallguy




PostPosted: Tue Apr 22, 2008 11:19 am   Post subject: RE:Help Making A Deck Of Cards

just do an array from 1 to 13
1 = ace
2-10 = regluar cards
11 = jake
12=queen
13 = king

and if ur making black jack, make 2 arrays that give out random numbers, convert them (king, jake etc), put them together, and display them

is this ur final?
Psychotogen




PostPosted: Tue Apr 22, 2008 11:22 am   Post subject: Re: Help Making A Deck Of Cards

Nope, just an assignment
Tallguy




PostPosted: Tue Apr 22, 2008 11:29 am   Post subject: RE:Help Making A Deck Of Cards

do u have to use arrays? u can do it with a for statement , and have a randint to display the cards
Psychotogen




PostPosted: Tue Apr 22, 2008 11:33 am   Post subject: Re: Help Making A Deck Of Cards

Yeah but Harrison doesn't help much it's a little more complicated than that =P hahah
Tallguy




PostPosted: Tue Apr 22, 2008 11:38 am   Post subject: RE:Help Making A Deck Of Cards

yah Harrison isn't that bad of a teacher though, u could use a 2d array but it'll be harder
richcash




PostPosted: Tue Apr 22, 2008 12:58 pm   Post subject: Re: Help Making A Deck Of Cards

The Turing FAQ will show you how to represent your cards. Obviously, after you have the suit and face value in numerical form you might want to convert them into something meaningful when outputting (eg 10 = "Jack", 11 = "Queen", 12 = "King" and 0 = hearts, 1 = spades, etc).

To select a random card from the deck: get a random value (using Rand.Int) between 0 and 51, select the card at that index number in the array, then switch that card/element with the last card in the array. Now, that last card has been "used" and you don't want it to repeat. So, since you moved it to the end, either make your "deck" a flexible array so you can delete that element at the end each time OR make a variable to keep track of how many cards are left in your deck and randomize from 0 to that number each time you need a new value (so "used" cards at the end will not be have their index selected).

Alternatively, you could do all randomizing beforehand and make a "virtual" shuffled deck/array, which means you just take cards off the top and keep track of what position you are at in the array (or use a flexible array). One way to "shuffle" would be to go through the array starting at 0, get a random value between the current index number and 51, then switch the card at the current index number with the card at the random value's index number.

If you need help with that explanation then make an attempt, post some code, and I/someone will help you with specific code.
Tallguy




PostPosted: Wed Apr 23, 2008 9:20 am   Post subject: RE:Help Making A Deck Of Cards

wow thats really good, i didn't think of that
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: