Results 1 to 8 of 8
  1. #1
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default 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

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default 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.

  3. #3
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default 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

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default 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.

  5. #5
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..

    heres what I got so far

    Java 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

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default 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.
    Java 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.

  7. #7
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..

    thanks, ill give it a go

  8. #8
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..

    Here's what I have so far for even:

    Java 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?
    Last edited by NoobieCode; 04-11-2013 at 05:53 AM.

Similar Threads

  1. Replies: 4
    Last Post: 03-28-2013, 08:40 PM
  2. what is wrong with this shuffle method??
    By javaa in forum New To Java
    Replies: 3
    Last Post: 09-06-2012, 02:30 AM
  3. Replies: 2
    Last Post: 03-23-2012, 04:53 AM
  4. Using main method to start off app
    By garrym in forum New To Java
    Replies: 3
    Last Post: 04-12-2011, 11:17 PM
  5. Shuffle Group Method
    By xelo in forum New To Java
    Replies: 6
    Last Post: 01-05-2009, 07:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •