• (2 Pages)
  • +
  • 1
  • 2

How to make a poker game in java creates, evaluates, and compares 5 card poker hands. Rate Topic: ***** 1 Votes

#16 nemacbgd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-January 14

Posted 10 January 2014 - 03:03 PM

In which program to run these codes? tried in Eclipse but fail to start the game, please help.
Was This Post Helpful? 0
  • +
  • -

#17 joezimmy54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-April 15

Posted 07 April 2015 - 11:52 AM

I dont no how to do the main code i used what was shown here but there are two other things in here as tests...do i add the other two as well or do i just use the one that says main....cuz my program is blowing up!
Was This Post Helpful? 0
  • +
  • -

#18 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 11771
  • View blog
  • Posts: 46,320
  • Joined: 12-June 08

Posted 07 April 2015 - 11:55 AM

The code seems straight forward. Three classes and a main to use the three classes. Perhaps start a help thread in the 'java' forum (to the right and *NOT* the tutorial section), post your code, and your errors so folks can help you out.
Was This Post Helpful? 0
  • +
  • -

#19 joezimmy54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-April 15

Posted 07 April 2015 - 11:59 AM

I have all three of the other classes written out all I am having troubles with is the main...I posted a screenshot of the main part from the code on here..is this the only part i need to use?

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#20 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 11771
  • View blog
  • Posts: 46,320
  • Joined: 12-June 08

Posted 07 April 2015 - 12:02 PM

I am not sure what the screen shot of the main code from this tutorial is for, but okay.

If your main uses the three classes then yes.. you'll need that code as well.

The tutorial walks through options code, and does a pretty good job explaining what goes where. Did you skim the tutorial, or just go to yoinking the code?
Was This Post Helpful? 0
  • +
  • -

#21 joezimmy54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-April 15

Posted 07 April 2015 - 12:10 PM

What i am asking is, is that code the only thing that needs to be in the "Main" part of the code?

And i read through it.
Was This Post Helpful? 0
  • +
  • -

#22 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 11771
  • View blog
  • Posts: 46,320
  • Joined: 12-June 08

Posted 07 April 2015 - 12:11 PM

What else are you expecting? The Main is just testing the object creation and hand comparison.
Was This Post Helpful? 0
  • +
  • -

#23 joezimmy54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-April 15

Posted 07 April 2015 - 12:12 PM

Alright thank you for the help.
Was This Post Helpful? 0
  • +
  • -

#24 CalPang  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-March 16

Posted 15 March 2016 - 04:22 AM

Hi, I found a few bugs, please update the content. I will provide the correct code below.

1) toString() method in Card

It should be rank minus one as you are trying to access the 0 index.

@Override
public String toString() {
return ranks[rank-1] + "of" + suits[suit-1];
}

I tested the above with this main method.

public static void main(String[] args) {
Deck d = new Deck();
System.out.println(d.cards.size());
for(Card c: d.cards) {
System.out.println(c.toString());
}
}

2) Constructor for card is short, not int. And deck is being initialized using int, hence the error.

Card(int suit, int rank) {
this.rank = rank;
this.suit = suit;
}

I'll continue to update this post as I go on with the tutorial.

Thanks,
Cal
Was This Post Helpful? 0
  • +
  • -

#25 CalPang  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-March 16

Posted 17 March 2016 - 05:09 AM

3) This does not check the last card in your hand. It will check the first card at index 0, and last card it will check will be at index 3 (because x < 4, which means the last index is 3), hence the last card in index 4 will not be checked

boolean flush=true; //assume there is a flush

for (int x=0; x<4; x++) {
if ( cards[x].getSuit() != cards[x+1].getSuit() )
flush=false;
}

The correct code should be:

for (int i = 0; i < 4; i++) {

if (i == 3) {
if (cards[i].getSuit() != cards[i+1].getSuit()) {
flush = false;
}
break;
}

if (cards[i].getSuit() != cards[i+1].getSuit()) {
flush = false;
break;
}
}

If you want to prove that this works, simply copy the below main method and test it out for yourself:

public static void main(String[] args) {
boolean check = true;
int[] array = {1,1,1,1,1};

System.out.println(array.length);

for (int i = 0; i < 4; i++) {

System.out.println("I is " + i + " and value: " + array[i]);
// This will check the last card in your hand
if (i == 3) {
System.out.println("I is " + (i+1) + " and value: " + array[i+1]);
if (array[i] != array[i+1]) {
check = false;
break;
}
}
if (array[i] != array[i+1]) {
check = false;
break;
}
}
System.out.println(check);
Was This Post Helpful? 0
  • +
  • -

#26 CalPang  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-March 16

Posted 17 March 2016 - 06:56 AM

4) The static method rankAsString prints incorrect rank

public static String rankAsString(int rank) {
return ranks[rank];
}

For example:

If your hand was:

Queen of clubs
Jack of hearts
Queen of diamonds
Ace of clubs
10 of spades

then it would print "Pair of King 's" instead of "Pair of Queen 's"

The correct rankAsString method shown below:

public static String rankAsString(int rank) {
return ranks[rank-1];
}
Was This Post Helpful? 0
  • +
  • -

#27 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 11771
  • View blog
  • Posts: 46,320
  • Joined: 12-June 08

Posted 17 March 2016 - 07:00 AM

When replying to a thread - be it one seven years old or a new one - please use the code tag button in the editor.

Select the portion of your text that is code and click the 'code' button.
Was This Post Helpful? 0
  • +
  • -

#28 CalPang  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-March 16

Posted 17 March 2016 - 07:40 AM

View PostCalPang, on 17 March 2016 - 06:56 AM, said:

4) The static method rankAsString prints incorrect rank

public static String rankAsString(int rank) {
return ranks[rank];
}

For example:

If your hand was:

Queen of clubs
Jack of hearts
Queen of diamonds
Ace of clubs
10 of spades

then it would print "Pair of King 's" instead of "Pair of Queen 's"

The correct rankAsString method shown below:

public static String rankAsString(int rank) {
return ranks[rank-1];
}


Please discard the above. Here is the corrected code Card class.

/**
* Created by Cal on 15/03/2016.
*/
public class Card {

private int rank, suit;
private static String[] suits = {"hearts","spades","diamonds","clubs"};
private static String[] ranks = {"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};

Card(int suit, int rank) {
this.suit = suit;
this.rank = rank;
}

@Override
public String toString() {
return ranks[rank] + " of " + suits[suit];
}

public int getRank() {
return rank;
}

public void setRank(short rank) {
this.rank = rank;
}

public int getSuit() {
return suit;
}

public void setSuit(short suit) {
this.suit = suit;
}

// This is a utility method
// saves me from having to ParseInt()
public static String rankAsString(int rank) {
return ranks[rank];
}


public static void main(String[] args) {
for (int i = 0; i < suits.length; i++) {
System.out.println(suits[i]);
}
}
}
Was This Post Helpful? -1
  • +
  • -

#29 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 11846
  • View blog
  • Posts: 44,462
  • Joined: 27-December 08

Posted 17 March 2016 - 09:19 AM

Please remember to use code tags when posting code: :code:.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2