# Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..

• 04-11-2013, 02:37 AM
NoobieCode
Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
Hello. I'm making a Poker Deck program implementing arrays. Im really stuck on how to shuffle, cut, and deal cards.

I understand I dont have code...I dont know how or where to start. Im new to arrays and im really confused. Simple hints will be awesome. Thanks!

for the shuffle method-This method will re-arrange the cards that are in the deck. The idea is that the deck will be divided into two "packets" -- the top half and the bottom half. The new array of cards will consist of: the first card from the top packet, followed by the first card from the bottom packet, followed by the second card from the top packet, followed by the second card from the bottom packet, etc. Important: If there are an odd number of cards, the top packet should have one more card than the bottom packet. Remember that the top of the deck is considered to be the front of the array.

EX: number of cards = 8

A B C D E F G H ==shuffle=== AE BF CG DH
0 1 2 3 4 5 6 7

EX: number of cards = 5

A B C D E ===Shuffle=== AD BE C
0 1 2 3 4

for the deal out cards method- This method will remove the specified number of cards from the top of the deck and return them as an array. For example, if the parameter is 4, then the first four cards in the deck will be returned as an array of size 4. Important: The cards will be removed from the front of the "cards" array, not the back.

for the cut method-This method divides the deck into two subpackets: The part above the specified position, and the part that is at the specified position or below. The two subpackets are reversed (the top packet is placed on the bottom and the bottom packet is placed on the top.) So, the card at the originally selected position becomes the "front" of the deck. The position value uses 0-based indexing as usual, so the card at the top of the deck (to the left in the diagrams) is at position 0.

EX: A B C D E F G H ===cut in position 4 == E F G H A B C D
0 1 2 3 4 5 6 7
• 04-11-2013, 03:31 AM
Junky
Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
Are these the instructions for the assignment provided to you? If so then you have been provided with the algorithm. All you need to do is code it. Note: deriving an algorithm is the hardest part, coding is simple.

Do you understand arrays? Do you understand how to create arrays, access elements in the array (get items out of an array or add items to an array)? If so then writing the code should not be a problem.

For shuffle you will need two counters (one for the top half, one for the bottom half). Copy the element at "top" into new array, copy element at "bottom" into a new array, increment both counters and repeat. Only issue is for an odd number of elements but work on that after you have it working for even elements.
• 04-11-2013, 04:03 AM
NoobieCode
Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
How would you do cut method and deal method...personally for me I think algorithm is ok and coding is hard especially since im not sure on syntax and Im new to it all
• 04-11-2013, 04:24 AM
Junky
Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
Have you finished the shuffle method? Get that working and it may give you some ideas on how to do the other methods.
• 04-11-2013, 04:56 AM
NoobieCode
Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
heres what I got so far

Code:

```                        Card[] even_shuffle = new Card[cards.length];  //cards is the array ive made to hold all the card values and suits                         Card[] top = new Card [(cards.length)/2];                         Card[] bottom = new Card [(cards.length)/2];                         for (int i = 0; i<cards.length/2; i++){                                                   top[i] = cards [i]                                                   }                                             for (j = cards.length/2 ; j < cards.length; j++){                       bottom[j] = cards[j]                     }                     for (shuffle = 0; shuffle <cards.length; shuffle++){                   even_shuffle[shuffle] =  // confused about how to put it together                     }```
how do I go about adding values back to a new array that shuffled
• 04-11-2013, 05:13 AM
Junky
Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
You only need one new array: the shuffled array. You will only need a single loop that iterates "original array length / 2" times.
You will need 2 counters as mentioned before.
Code:

```loop {     copy top element into shuffled array     copy bottom element into shuffled array     inc top     inc bottom } return shuffled array (or assign it to variable holding original array)```
Note that the above pseudocode basically does what your instructions said:
The new array of cards will consist of: the first card from the top packet, followed by the first card from the bottom packet, followed by the second card from the top packet, followed by the second card from the bottom packet, etc.
• 04-11-2013, 05:22 AM
NoobieCode
Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
thanks, ill give it a go
• 04-11-2013, 05:31 AM
NoobieCode
Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
Here's what I have so far for even:

Code:

```                         Card[] even_shuffle = new Card[cards.length];  //creating new array with length                                         int top = 0;                          //initialize top                                                                 for (int index = 0; index < cards.length; index+2){  //going through the even index                                 even_shuffle[index] = cards [top];                                  top++; }                       int bottom = cards.length/2;  //initialize bottom                //going through odd index                       for (int index_two = 1; index_two < cards.length; index_two+2){                           even_shuffle[index] = cards[bottom];                           bottom++; }                                                                                      }                   return;                         }```

What do you think?