Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:41:27+00:00 2026-06-02T19:41:27+00:00

I am working on a poker game. So far I am stuck on comparing

  • 0

I am working on a poker game. So far I am stuck on comparing poker hands. I sort of have an idea on how to do it but I am not sure what is wrong with my code. Can somebody please point out what’s wrong?

So let me give a brief description of what my code is doing.

My other part of the program will go through the cards in my hand and list the frequency of a card value in an array.

h = Hearts
c = Clubs
d = Diamonds
s = Spades
d4 = 4 of Diamond

So let’s say in my hand I have
c3, h4, d4, s4, 2d
I will call the other part of my program to read the cards in my hand and return a tally array. The tally array for my hand above will be [0,0,1,1,3,0,0,0,0,0,0,0,0,0] So pretty much what this array is saying is that my hand has one 2, one 3 and three 4.

Now here is my method on trying to find Three of a Kind, it should return false for full house (which is three of a kind plus a pair)

public boolean hasThreeOfAKind() {
    int [] temp;
    temp = this.getCounts();
    for (int i = 0; i< temp.length; i++){
        if (temp [i] == 3 ){
            for (int j = 0; j < temp.length ; j++)
                if ( temp [j] != 2){
                    return true;
                }
        }
    }return false;

So what I am trying to do above is first, I run through the array, and if if there is any 3. If there is a 3, I run through the array again and see if there is a 2. and if there is not a 2, then I know it is three of a kind. If there is a 2, then it is full house and I should return false. I think my logic is correct, but there is something wrong with my code.

And the second hand that I am having trouble is how to determine if my hand has EXACTLY one pair. It only return true if there is only one pair. Return false if there are two pairs etc.

public boolean hasOnePair() {
    int [] temp;
    temp = this.getCounts();

    for (int i = 0; i< temp.length; i++){
        if (temp [i] == 2 ){
            return true;
        }
    }return false;

For this one, I am thinking of sort the value in the array either in descending or ascending order. If I chose the descending order, I first read the array and see if there is a 2, then I could scan the next one and see if the next value after the first 2 is also a 2. If there is another 2, then it would return false.

Can somebody please take a look at my code and point out what’s wrong? Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:41:30+00:00Added an answer on June 2, 2026 at 7:41 pm

    In your hasThreeOfAKind() you have the following error:

    for (int j = 0; j < temp.length ; j++) 
      if ( temp [j] != 2){ 
        return true; 
      } 
    } 
    

    This will return true the first time it finds a non-2 j (which will be statisfied with the 3 you just checked above it — thus returns true for a full house. You need instead:

    boolean foundTwo = false;
    for (int j = 0; j < temp.length ; j++) 
      if ( temp [j] == 2){ 
        foundTwo = true; 
      }
    } 
    if (!foundTwo) {
      return false;
    }
    

    Similarly for the other: you need to check if you find another 2 that is different from the one you already found:

    for (int i = 0; i< temp.length; i++) {  
      if (temp [i] == 2 ){
        boolean foundAnother = false;
        for (int j = 0; j< temp.length; j++) { 
          if (i != j && temp [j] == 2 ){
            foundAnother = true;  
          }  
        }
        if (!foundAnother) {
          return true;
        }
      }  
    }
    return false;  
    

    Another thing you could do is have filters for each recognized hand: a pair-filter, a three-filter, a full-house-filter, etc. and run all those filters through the hand. Don’t worry if there is a better (higher value) match, just see which filters return true (found the pattern they were looking for) and select the highest point value among the ones that passed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a Poker-iPhone-Application. Everything works just fine but I would like
I'm currently working on a small 2D game-engine in C++, but I am now
I am currently working on a Poker java game exercise, and I get this
I am working on a project to develop a poker bot, I have to
I have the code here working fine except that all the non-power of 2
I am currently working on a poker hand history parser as a part of
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
I'm a CS master student, and next semester I will have to start working
I am currently working on a GPS tracking App (only the distance, not storing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.