473,379 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

I need help with a poker simulator.

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. }
Sep 17 '09 #1
4 7294
r035198x
13,262 8TB
Please use code tags if you have to post code.
What is your question?
Sep 18 '09 #2
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.
Sep 18 '09 #3
The question is how do I move on from there to complete the program.
Sep 18 '09 #4
Frinavale
9,735 Expert Mod 8TB
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.
Sep 21 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alex Vinokur | last post by:
C++ Simulator of a Universal Turing Machine can be downloaded at : * http://alexvn.freeservers.com/s1/utm.html * http://sourceforge.net/projects/turing-machine/ The program simulates a...
1
by: Gandu | last post by:
I apologize if this is not the appropriate newsgroup to post this message. Could someone please tell me a good place to get an an Aloha protocol simulator source code(C++) that is well-documented...
0
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college...
0
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college...
13
by: lane straatman | last post by:
I'm trying to figure out what data type is appropriate to represent a card in a game. The idea that I thought was going to work was a struct, foo, with two integer fields and two fields of char...
27
by: Simon Biber | last post by:
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a good description of how to count the frequency of different types of poker hands using a mathematical approach. A sample...
3
by: DanielJohnson | last post by:
I was wondering if anyblody can suggest me a network simulator written in python in which I can add on my own code and extend its functionality. I am looking for a simulator which will simualte...
18
by: activearun.83 | last post by:
Hi everyone, Can anyone give some idea about developing an 8085 simulator program in C? What techniques can be handled to develop this?
9
by: teejayem | last post by:
I am looking for some help! I am currently developing a new game for an online community. The game is called Pokino which ishalf bingo and half poker. Wierd eh?! Anyway... The final part...
5
by: tumundoya | last post by:
in my site: when I go with mouseover on the poker image on the poker page all the DIVS below dissapear. What am I doing wrong? Click on the poker image to go to the poker page and then hover over...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.