Hi, I tried to write a small routine to compute the EHS for some hands, but I keep getting inconsistent results. For example:
As imput: Hand: Ad Qc
Flop: 3h 4c Jh (like in "Opponent Modeling in Poker")
My result is:
[18:00:04] HS: 0.5851063829787234
[18:00:04] Ppot: 0.20844566061957367
[18:00:04] Npot: 0.27369265780332974
[18:00:04] EHS: 0.511449836010428
which seems to be correct, according to the paper named above.
But in
http://www.poker-ai.org/archive/pokerai.org/pf3/viewtopic57d8.html?f=3&t=2764&view=next I saw some EHS values calculated by indiana, so I tried to verify my code with these value.
AsAd 4cJh9s --> EHS: 0.853 worked correct for me:
...
[18:04:46] EHS: 0.8530260981694839
But some inputs seem to result in wrong EHS values, just like:
AhJd JcJhAs --> EHS: 0.994
my results: EHS: 0.9881422924901185
Can you find any error in my code, except the quick and dirty style?
Code:
Deck deck = new Deck();
deck.shuffle();
List<Card> d = deck.deal(52);
Card[] de = d.toArray(new Card[d.size()]);
int[] distribution = new int[3];
int[][] HP = new int[3][3];
int[] HPTotal = new int[3];
int[] HPTotal_ = new int[3];
int ind = 0;
int index = 0, ahead = 0, tied = 1, behind = 2 ;
Hand myHand = new Hand("Ah Jd");
List<Card> board = new ArrayList<>();
board.add(new Card("As"));
board.add(new Card("Jc"));
board.add(new Card("Jh"));
for (int i = 0; i < de.length-1; i++) {
Card o1 = de[i];
if (board.contains(o1) || myHand.contains(o1)) {
continue;
}
for (int j = i+1; j < de.length; j++) {
Card o2 = de[j];
if (board.contains(o2) || myHand.contains(o2) || o1.equals(o2)) {
continue;
}
//index++;
Hand h1 = new Hand(board);
h1.addCards(myHand.getCards());
Hand h2 = new Hand(board);
h2.addCard(o1);
h2.addCard(o2);
HandValue v1 = new HandValue(h1);
HandValue v2 = new HandValue(h2);
// System.out.println(index+": Checking "+ c1.toString()+ " "+c2.toString() +"-> "+ v1.getDescription()+"("+v1.getValue()+")"+ " vs. "+v2.getDescription()+"("+v2.getValue()+")");
if (v1.getValue() > v2.getValue()) {
distribution[0]++;
index = ahead;
} else if (v1.getValue() == v2.getValue()) {
distribution[1]++;
index = tied;
} else if (v1.getValue() < v2.getValue()) {
distribution[2]++;
index = behind;
}
for (int k = 0; k < de.length; k++) {
Card turn = de[k];
if (board.contains(turn) || myHand.contains(turn) || o1.equals(turn) || o2.equals(turn)) {
continue;
}
for (int l = k; l < de.length; l++) {
Card river = de[l];
if (board.contains(river) || myHand.contains(river) || o1.equals(river) || o2.equals(river) || turn.equals(river)) {
continue;
}
board.add(0,river);
board.add(0,turn);
h1 = new Hand(board);
h1.addCards(myHand.getCards());
h2 = new Hand(board);
//System.out.println(h2.toString());
board.remove(0);
board.remove(0);
h2.addCard(o1);
h2.addCard(o2);
v1 = new HandValue(h1);
v2 = new HandValue(h2);
//
//
if (v1.getValue() > v2.getValue()) {
HP[index][ahead] += 1;
} else if (v1.getValue() == v2.getValue()) {
HP[index][tied] += 1;
} else if (v1.getValue() < v2.getValue()) {
HP[index][behind]+= 1;
//System.out.println(": Checking o1:"+ o1.toString()+ " o2:"+o2.toString() +"-> "+ v1.getDescription()+"("+h1.toString()+")"+ " vs. "+v2.getDescription()+"("+h2.toString()+")");
//System.out.println("Board: "+board);
}
ind += 1;
//HPTotal_[index] = HP[0][index]+HP[1][index]+HP[2][index];
HPTotal[index] = HP[index][ahead]+HP[index][tied]+HP[index][behind];
}
}
}
}
for (int i = 0; i < distribution.length; i++) {
System.out.println(distribution[i]);
}
double HS = ((double)distribution[ahead]+ (double)distribution[tied]/2);
HS = HS / ((double)distribution[ahead]+(double)distribution[tied]+(double)distribution[behind]);
for (int i = 0; i < HP.length; i++) {
System.out.println(HP[i][ahead]+"\t"+HP[i][tied]+"\t"+HP[i][behind]+"\t"+HPTotal[i]);
}
System.out.println("HS: "+HS);
/* Ppot: were behind but moved ahead. */
double Ppot = ((double)HP[behind][ahead]+(double)HP[behind][tied]/2.0 +(double)HP[tied][ahead]/2.0);
if (Ppot != 0) Ppot /= ((double)HPTotal[behind]+(double)HPTotal[tied]/2.0);
double Npot = ((double)HP[ahead][behind]+(double)HP[tied][behind]/2.0 +(double)HP[ahead][tied]/2.0) / ((double)HPTotal[ahead]+(double)HPTotal[tied]/2.0);
double EHS = HS + (1 - HS) * Ppot - HS * Npot;
System.out.println("Ppot: "+Ppot);
System.out.println("Npot: "+Npot);
System.out.println("EHS: "+EHS);