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

    Default Arrays-Poker Simulation Methods help/hints

    Hi I am writing a poker code that mainly implements the use of Arrays.
    I am kinda confused on these certain methods I have to make.
    Please help me correct something If I am doing something wrong.
    Thank you.

    ---------------------------------------------
    Constructor Summary

    Card(int value, int suit)
    Standard constructor.

    Method Summary

    int getSuit()
    "Getter" for suit of Card.
    int getValue()
    "Getter" for value of Card.
    java.lang.String toString()
    Returns the name of the card as a String.

    Constructor Detail
    Card

    public Card(int value, int suit)
    Standard constructor.
    Parameters:
    value - 1 through 13; 1 represents Ace, 2 through 10 for numerical cards, 11 is Jack, 12 is Queen, 13 is King
    suit - 0 through 3; represents Spades, Hearts, Clubs, or Diamonds

    Method Detail

    getValue

    public int getValue()
    "Getter" for value of Card.

    Returns:
    value of card (1-13; 1 for Ace, 2-10 for numerical cards, 11 for Jack, 12 for Queen, 13 for King)
    getSuit



    public int getSuit()
    "Getter" for suit of Card.

    Returns:
    suit of card (0-3; 0 for Spades, 1 for Hearts, 2 for Clubs, 3 for Diamonds)



    ----------------------------------------------------

    Java Code:
    
    /**[B]public Deck()[/B] -- This constructor initializes the Deck with 52 card objects, 
    representing the 52 cards that are in a standard deck.  The cards must be ordered 
    as in the diagram below: **/
    
    public class Deck {
    
    	private Card[] cards;
    
    	public Deck() { 
    		this.cards = new Card[52]; //index [0,51]
    
    		int index = 0;
    		for (int suit = 0; suit <= 3; suit++){
    			for (int value = 1; value <= 13; value++){
    				this.cards[index] = new Card(value, suit);
    				index++;
    
                       }
             }
    }
    
    
    
    /** Important:  The FIRST card in your array should be the Ace of Spades, 
    and the LAST card should be the King of Diamonds. 
     Note that in the picture above, the Ace of Spades 
    is at the TOP of the deck, which is to the left. **/
    
     
    
    public Deck(Deck other) /** -- Standard copy constructor.  
    Note that it is okay to make a shallow copy of the array of cards.  
    (The Card class is immutable, so aliasing Cards is not a problem.) **/
    
    this.cards = other.cards;
    
     }
    
    
    
    
    public Card getCardAt(int position) /**-- Returns the card that is at the specified position in the array.  
    (Uses the usual 0-based indexing.)**/
    
    int position = this.cards.getValue;   //Don't understand how this getter works.
    
    return;
    }
    
     
    
    public int getNumCards() /** -- Returns the size of the array of Cards.  (It starts off equal to 52, but becomes smaller as cards are dealt from the deck.)**/
    
    this.cards = new Cards [this.cards.length-i]  //Confused about how to do this
    
    return;
     }
    Last edited by NoobieCode; 04-10-2013 at 07:11 AM.

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Arrays-Poker Simulation Methods help/hints

    Hi NoobieCode, what is the confusion?

    The code above just shows the Deck class. Have you started the Card class? If so could you post your attempt so we can assist.

    Regards.

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

    Default Re: Arrays-Poker Simulation Methods help/hints

    Hi.

    Im confused, in terms of syntax, on how to write the copy method, getNumCards, and getCartAt methods.

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

    Default Re: Arrays-Poker Simulation Methods help/hints

    I only need to implement the Deck Class...It consists of these methods which I am struggling on:


    public Deck() -- This constructor initializes the Deck with 52 card objects, representing the 52 cards that are in a standard deck. The cards must be ordered as in the diagram below:


    public Deck(Deck other) -- Standard copy constructor.


    public Card getCardAt(int position) -- Returns the card that is at the specified position in the array. (Uses the usual 0-based indexing.)

    public int getNumCards() -- Returns the size of the array of Cards. (It starts off equal to 52, but becomes smaller as cards are dealt from the deck.)
    Last edited by NoobieCode; 04-10-2013 at 10:18 AM.

  5. #5
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Arrays-Poker Simulation Methods help/hints

    • The diagram did not attach so I can't help you with this just yet.
    • Is this a deep or shallow copy? I'm assuming deep in which case I would expect a copy construct within the card class as well.
    • getCardAt() just returns the instance of Card at the required position within the array.
    • The implementation depends on the type of array you are using, whether this is fixed or a type of list. As you are using a fixed size array then there needs to be a way of either removing a card from the pack as it is dealt or to record the number of cards which have been dealt.


    Regards.

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

    Default Re: Arrays-Poker Simulation Methods help/hints

    shallow copy

    i think i got it. thanks...

    any ideas on how I would go about shuffling, dealing, and cutting the deck?

    Im bad with algorithms and Im just beginning.

  7. #7
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Arrays-Poker Simulation Methods help/hints

    A lot of this is down to personal interpretation, how would you do this with a real set of cards? For example each person would have their own way of shuffling, dealing and cutting the deck.
    • One solution to shuffle the pack would be to randomly switch each card in the pack. You could also switch one random card with another a random number of times.
    • To deal a card you would remove a card from start or end of the card array and assign it to a player. How you want to remove the card from the array can be done by nulling the position or reducing the size of the array.
    • As for cutting the deck, would you like to split the pack or use this function to obtain a random card?


    Regards.

Similar Threads

  1. Arrays and Methods
    By jmscarlet9 in forum New To Java
    Replies: 3
    Last Post: 03-27-2012, 02:29 AM
  2. Poker Simulation (shuffling a deck of cards?)
    By StateofMind in forum New To Java
    Replies: 4
    Last Post: 04-06-2010, 08:59 PM
  3. Arrays and methods
    By namie in forum New To Java
    Replies: 3
    Last Post: 10-05-2009, 09:43 AM
  4. Arrays & Methods
    By TheRocket in forum New To Java
    Replies: 1
    Last Post: 12-10-2008, 07:37 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
  •