I am using the this hand evaluator found here for nodejs:
https://github.com/chenosaurus/poker-evaluator
It works great and it's really fast at evaluating hands. However, I want to use it to write a script to caluclate the % chance of winning a hand against an opponent.
For example, two players have two hands: [Ac, 8c] Vs [9d,9h] etc.
I've tried doing a loop through all the possible board cards like:
var cards = [
"2c","3c","4c","5c","6c","7c","8c","9c","Tc","Jc","Qc","Kc","Ac",
"2d","3d","4d","5d","6d","7d","8d","9d","Td","Jd","Qd","Kd","Ad",
"2h","3h","4h","5h","6h","7h","8h","9h","Th","Jh","Qh","Kh","Ah",
"2s","3s","4s","5s","6s","7s","8s","9s","Ts","Js","Qs","Ks","As",
];
var hand = ["As", "Ks"];
var trials = 0;
for(i=0;i<cards.length;i++) {
for(j=i+1;j<cards.length;j++) {
for(k=j+1;k<cards.length;k++) {
for(l=k+1;l<cards.length;l++) {
for(m=l+1;m<cards.length;m++) {
trials++;
var nh = hand.slice();
nh.push(cards[i]);
nh.push(cards[j]);
nh.push(cards[k]);
nh.push(cards[l]);
nh.push(cards[m]);
PokerEvaluator.evalHand(nh);
}
}
}
}
}
Obviously this isn't finished (it doesn't check the rank of the hand or compare it), but this is the only way I know to evaluate all possible board combinations for the two hands.
It's very slow, despite the algorithm being able to evaluate millions of hands per second. Is there a better way to check two hands against each other, instead of using for loops on all possible evaluations?