Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HandPowerRanker can't detect A-5 Straight. #16

Open
garzy opened this issue Feb 26, 2016 · 2 comments
Open

HandPowerRanker can't detect A-5 Straight. #16

garzy opened this issue Feb 26, 2016 · 2 comments

Comments

@garzy
Copy link

garzy commented Feb 26, 2016

This is because A can be maximun (T,J,Q,K,A) an minimum (A,2,3,4,5). You must search explicity for A-5 Straight if in your Straight check you found an Ace.

Replace getStraightNumber method whith this two.

private CardNumber getStraightNumber(List cardNumbers) {
CardNumber straightNumber = null;
int straightCount = 1;
int prevPower = 0;
Collections.sort(cardNumbers, cardNumberComparator);
boolean aceFounded = false;
for (CardNumber cardNumber : cardNumbers) {
if (cardNumber == CardNumber.ACE) {
aceFounded = true;
}
if (cardNumber.getPower() == prevPower + 1) {
straightCount++;
if (straightCount >= 5) {
straightNumber = cardNumber;
}
} else {
straightCount = 1;
}
prevPower = cardNumber.getPower();
}
if (straightNumber == null && aceFounded) {
return getLowestStraightNumberWithAce(cardNumbers.subList(0, cardNumbers.size() - 1));
}
return straightNumber;
}

private CardNumber getLowestStraightNumberWithAce(List<CardNumber> fromTwoList) {
    CardNumber straightNumber = null;
    int straightCount = 1;
    int prevPower = 1; // ACE
    for (CardNumber cardNumber : fromTwoList) {
        if (cardNumber.getPower() == prevPower + 1) {
            straightCount++;
            if (straightCount >= 5) {
                straightNumber = cardNumber;
            }
        } else {
            straightCount = 1;
        }
        prevPower = cardNumber.getPower();
    }
    return straightNumber;
}

(@see http://stackoverflow.com/questions/530208/function-to-determine-whether-a-poker-hand-is-a-straight)

@garzy
Copy link
Author

garzy commented Mar 12, 2016

Refixed method:

private static List getLowestStraightNumberWithAce(List fromTwoList) {
List result = new ArrayList<>();
result.add(CardNumber.ACE);
int prevPower = 1; // ACE
for (CardNumber cardNumber : fromTwoList) {
if (cardNumber.getPower() == prevPower + 1) {
result.add(cardNumber);
prevPower = cardNumber.getPower();
}
}
if (result.size() < 5) {
return null;
}
Collections.reverse(result); // mayor to minor (5,4,3,2,A)
return result;
}

@AdrianAcala
Copy link

Just to let you know, the code hasn't been updated in 3 years and there's a pull request in July 2015. This project is pretty dead. No license either, which sucks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants