Connecting Tech Pros Worldwide Help | Site Map

I need help with a poker simulator.

Newbie
 
Join Date: Sep 2009
Posts: 3
#1: Sep 17 '09
Expand|Select|Wrap|Line Numbers
  1. //My card class
  2. import java.util.Arrays;
  3. import java.util.Random;
  4.  
  5. public class Card
  6. {
  7.  //Attributes
  8.   private int suit;
  9.   private int value;
  10.  
  11.  //Constructors
  12.   //Default
  13.    public Card()
  14.    {
  15.     suit=0;
  16.     value=0;
  17.    }
  18.  
  19.   //Explicit
  20.     public Card(int suit, int value)
  21.     {
  22.      this.suit=suit;
  23.      this.value=value;
  24.     }
  25.  
  26.        if(suit == 0)
  27.          {
  28.           return ("heart");
  29.          }
  30.  
  31.        else if(suit == 1)
  32.         {
  33.          return ("spade");
  34.         }
  35.  
  36.        else if(suit == 2)
  37.         {
  38.          return ("club");
  39.         }
  40.  
  41.        else if(suit == 3)
  42.         {
  43.          return ("diamond");
  44.         }
  45.  
  46.  
  47.   public int getSuit()
  48.   {
  49.    return suit;
  50.   }
  51.  
  52.   public int getValue()
  53.   {
  54.    return value;
  55.   }
  56.  
  57.  
  58.  public String toString()
  59.  {
  60.   return (suit+ "," +value);
  61.  }
  62. }
  63.  
  64. //My deck class
  65. import java.util.Arrays;
  66. import java.util.Random;
  67.  
  68. public class Deck
  69. {
  70.  public static void main(String[] args)
  71.  {
  72.   int[] s=new int[4];
  73.   int[] v=new int[13];
  74.   Card[] c=new Card[13];
  75.  
  76.   Random gen=new Random();
  77.  
  78.  
  79.   for(int i=0; i<13; i++)
  80.      c[i]=new Card(gen.nextInt(13), gen.nextInt(4));
  81.   for(int i=0; i<5; i++)
  82.    System.out.println(c[i]);
  83.  }
  84. }
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Sep 18 '09

re: I need help with a poker simulator.


Please use code tags if you have to post code.
What is your question?
Newbie
 
Join Date: Sep 2009
Posts: 3
#3: Sep 18 '09

re: I need help with a poker simulator.


Poker Simulator. Implement a simulation of a popular casino game called video poker. The card deck contains 52 cards, 13 of each suit/ At the beginning of the game, the deck is shuffled. The top of the 5 cards are presented to the player. The player can reject none, some, or all of the cards. The rejected cards are replaced from the top of the deck. Now the hand is scored. Your program should pronounce it to be one of the following....No pair, one pair, two...up to Royal Flush. Now, you are required to use an array to hold your deck of the cards. Because each of your cards belongs to one of the four suits and has a value, you need a Card class that has two attributes. Your Card class is required to implement the Comparable interface so that the static sort method in the Arrays class can be used to sort an array of Cards to ascending order. How to shuffle a deck? Use a random generator to generate your 52 cards: use your generator to generate a number between 0 and 4 first for the suit, then generate a number between 1(inclusive) and 13(inclusive) for the value, and then store your Card in your array. How do you evaluate a hand? Order the hand by using the static sort method from the arrays class first and then make the comparison from highest hand(royal flush) to the lowest hand(no pair)...
Shuffle your cards, pick the first five to display, ask the player which cards of the five should be discarded, discard the cards, pick the same number of the cards from the top of the deck, evaluate and report the rank of the hand.
Newbie
 
Join Date: Sep 2009
Posts: 3
#4: Sep 18 '09

re: I need help with a poker simulator.


The question is how do I move on from there to complete the program.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#5: Sep 21 '09

re: I need help with a poker simulator.


I don't even think that the code you posted will compile. You have an if/elseif/else block outside of a method.

Anyways, you have a card class, and a deck class.


Now you need to write a Main program that will use the Deck Class to deal out Hands of cards.

So I would think that you would need to either create another class (Hand) or use arrays (as suggested).

Hands would probably be the better way from an OOP point of view.

It really helps me to understand what to do if I write down what is done step by step.

For example, the program starts:
  • The system shuffles the deck
  • The system deals out 5 cards to 5 hands
  • Each player decides what cards to discard
  • The system starts with player 1 and asks for the cards they wish to return
  • The player returns the cards
  • The system gives them back the same amount of cards that they returned by selecting off the top of the deck
  • Each hand is evaluated to determine which hand wins.

Each noun (I underlined some of them) is a class and each verb (I italicized some of them) is a task that the class has to do. These tasks are the methods that you have to implement...the steps that occur is the "main" application method.

This technique is very helpful and should aid you in figure out what to do.


The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.
Reply