Open vitobellini opened 7 years ago
public RankableHand(Set<Card> c) throws HandRankingException{
if(c.size() < 5 | c.size() > 7){
String ex = "Between 5 and 7 unique cards required to construct instance. " + "Detected " + this.cards.size() + " cards";
throw new HandRankingException(ex);
}
this.cards=c;
calculateHandValue();
}
Ok the problem is here because we use this.cards before it's assigned. However my point is: how can I evaluate an hand in the last phase where I have my 2 holding cards and 5 community cards (3 flop + turn + river)? HandRankingException will always raise, it is counting 9 cards in that situation...
I've addressed this issue by checking the number of community cards in the following way in Player.java's calculateHandStatistics method.
if(gameState.getCommunityCards().size() == 3) {
Card u3 = remainingCards.get(boardCombi.get(0) - 1);
impliedPlayerCards.add(u3);
impliedEnemyCards.add(u3);
if(gameState.getCommunityCards().size() == 4) {
if (effectiveOdds) {
Card u4 = remainingCards.get(boardCombi.get(1) - 1);
impliedPlayerCards.add(u4);
impliedEnemyCards.add(u4);
}
}
}
I'll be waiting for your acknowledgement for the fix!
Hey Vito, Thanks for your interest in this project. Kind of busy atm. I'll review the issue this weekend and I'll get back to you with an answer asap!
Have a good week.
Hi Vito, A few things. Your code fix doesn't make sense because in your IF statement you're checking if there are 3 community cards, and then inside that logic bracket you are checking for 4 cards which will never happen, because you're already checking for 3. Thats problem #1. The second issue is that there is no bug in the code to begin with. You are setting the turn and the river, and then in the PokerGame class you're checking for the FUTURE hand value with player.calculateHandPotential(weightArray, 5, true, remainingCards); And obviously you can't check future hand values when its the river, right? So just remove that TRUE parameter on the river and it works. In other words, the code is fine, you just weren't using it correctly. But with your changes above, its definitely going to be broken.
Hi, I'm addressing a NullPointerException... I'm just trying to add turn a river card to my deck
` Card turn = new Card(Card.SUIT_SPADES, Card.RANK_5); Card river = new Card(Card.SUIT_HEARTS, Card.RANK_2); deck.removeCard(turn); deck.removeCard(river); List remainingCards = deck.getCards();
List<List> weightArray = HandRanker.getUniformWeightArray();
Exception in thread "main" java.lang.NullPointerException at RankableHand.(RankableHand.java:36)
at HandFactory.getHand(HandFactory.java:66)
at Player.calculateHandStatistics(Player.java:226)
at Player.calculateHandPotential(Player.java:139)
at PokerGame.main(PokerGame.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)