You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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;
}
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.
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;
}
(@see http://stackoverflow.com/questions/530208/function-to-determine-whether-a-poker-hand-is-a-straight)
The text was updated successfully, but these errors were encountered: