package com.bassoli.poker; public class HandPossibilities { /** * PREFLOP * 89 suited */ public static double eightOrNine(Hand hand, int n) //pair of your kind or better { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (cards[0].getValueInt() == cards[1].getValueInt()) return 0; double chance = (1 - (double)Probability.choose(44,n)/(double)Probability.choose(50,n)) * 100; return chance; } public static double eightsAndNines(Hand hand, int n) //2 pair of your kind or better { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (cards[0].getValueInt() == cards[1].getValueInt()) { return 0; } double chance = ((double) ( Probability.choose(3,1) * Probability.choose(3,1) * Probability.choose(44,n-2) //89*** + Probability.choose(3,2) * Probability.choose(44,n-2) * 2 //88*** or 99*** + Probability.choose(3,2) * Probability.choose(3,1) * Probability.choose(44,n-3) * 2 //889** or 998** + Probability.choose(3,3) * Probability.choose(48,n-3) * 2 //888** or 999** ) / Probability.choose(50,n)) * 100; return chance; } public static double twoEightsOrTwoNines(Hand hand, int n) //3 of your kind or better { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (cards[0].getValueInt() == cards[1].getValueInt()) { return 0; } double chance = ((double) ( Probability.choose(3,2) * Probability.choose(44,n-2) * 2 //88*** or 99*** + Probability.choose(3,2) * Probability.choose(3,1) * Probability.choose(44,n-3) * 2 //889** or 998** + Probability.choose(3,3) * Probability.choose(48,n-3) * 2 //888** or 999** ) / Probability.choose(50,n)) * 100; return chance; } public static double fullHouseEightNine(Hand hand, int n) //full house or better { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (cards[0].getValueInt() == cards[1].getValueInt()) { return 0; } double chance = ((double) ( Probability.choose(3,2) * Probability.choose(3,1) * Probability.choose(44,n-3) * 2 //889** or 998** + Probability.choose(3,3) * Probability.choose(48,n-3) * 2 //888** or 999** ) / Probability.choose(50,n)) * 100; return chance; } public static double fourKindEightNine(Hand hand, int n) //four of a kind { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (cards[0].getValueInt() == cards[1].getValueInt()) { return 0; } double chance = ((double) ( Probability.choose(3,3) * Probability.choose(48,n-3) * 2 //888** or 999** ) / Probability.choose(50,n)) * 100; return chance; } public static double flushChance(Hand hand, int n) //SS*** or better { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (!cards[0].getSuit().equals(cards[1].getSuit())) { return 0; } if (n == 5) { return 0; } double chance = ((double) ( Probability.choose(11,2) * Probability.choose(39,n-2) //SS*** + Probability.choose(11,3) * Probability.choose(39,n-3) //SSS** + Probability.choose(11,4) * Probability.choose(39,n-4) //SSSS* + Probability.choose(11,5) * Probability.choose(39,n-5) //SSSSS ) / Probability.choose(50,n)) * 100; return chance; } public static double flush(Hand hand, int n) { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (!cards[0].getSuit().equals(cards[1].getSuit())) { return 0; } double chance = ((double) ( Probability.choose(11,3) * Probability.choose(39,n-3) //SSS** + Probability.choose(11,4) * Probability.choose(39,n-4) //SSSS* + Probability.choose(11,5) * Probability.choose(39,n-5) //SSSSS ) / Probability.choose(50,n)) * 100; return chance; } public static double straight(Hand hand, int n) { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); SortHand.sort(cards); int difference = cards[0].getValueInt() - cards[1].getValueInt(); if ((difference > 0)&&(difference < 5)) { int multiplier = 5 - difference; if (cards[0].getValue().equals("A")) { multiplier = 1; } else if (cards[0].getValue().equals("K")||cards[1].getValue().equals("2")) { if (multiplier > 2) multiplier = 2; } else if (cards[0].getValue().equals("Q")||cards[1].getValue().equals("3")) { if (multiplier > 3) multiplier = 3; } double chance = ((double) ( 4*4*4*multiplier*Probability.choose(40,n-3) ) / Probability.choose(50,n)) * 100; return chance; } SortHand.sort_aceProvision(cards); int difference_ace = cards[0].getValueInt() - cards[1].getValueInt()%13; if ((difference_ace > 0)&&(difference_ace < 5)) { double chance = ((double) ( 4*4*4*Probability.choose(40,n-3) ) / Probability.choose(50,n)) * 100; return chance; } else { return 0; } } public static double openStraight(Hand hand, int n) { if (hand.getHandSize() !=2) return 0; if (n == 5) { return 0; } Card[] cards = hand.getCards(); SortHand.sort(cards); int difference = cards[0].getValueInt() - cards[1].getValueInt(); if ((difference > 0)&&(difference < 4)) { int multiplier = 4 - difference; if (cards[0].getValue().equals("A")) { double chance = ((double) ( 4*4*4*Probability.choose(40,n-3) ) / Probability.choose(50,n)) * 100; return chance; } else if (cards[0].getValue().equals("K")||cards[1].getValue().equals("2")) { if (multiplier > 1) multiplier = 1; } else if (cards[0].getValue().equals("Q")||cards[1].getValue().equals("3")) { if (multiplier > 2) multiplier = 2; } double chance = ((double) ( 4*4*multiplier*Probability.choose(44,n-2) ) / Probability.choose(50,n)) * 100; return chance; } SortHand.sort_aceProvision(cards); int difference_ace = cards[0].getValueInt() - cards[1].getValueInt()%13; if ((difference_ace > 0)&&(difference_ace < 4)) { double chance = ((double) ( 4*4*4*Probability.choose(40,n-3) ) / Probability.choose(50,n)) * 100; return chance; } else { double chance = ((double) ( 4*4*4*Probability.choose(40,n-3) ) / Probability.choose(50,n)) * 100; return chance; } } /** * PREFLOP * AA */ public static double threeKindAces(Hand hand, int n) //three of a kind or better { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (cards[0].getValueInt() != cards[1].getValueInt()) { return 0; } double chance = ((double) ( Probability.choose(2,1) * Probability.choose(48,n-1) //A**** + Probability.choose(2,2) * Probability.choose(48,n-2) //AA*** ) / Probability.choose(50,n)) * 100; return chance; } public static double fourKindAces(Hand hand, int n) //four of a kind { if (hand.getHandSize() !=2) return 0; Card[] cards = hand.getCards(); if (cards[0].getValueInt() != cards[1].getValueInt()) { return 0; } double chance = ((double) ( Probability.choose(2,2) * Probability.choose(48,n-2) //AA*** ) / Probability.choose(50,n)) * 100; return chance; } public static double pairingUpChance(Hand hand, Hand board, int n, boolean river) { int i = 0; if (river) { i = 1; } Card[] cards = hand.getCards(); if (PocketBoardAnalyzer.pairedUp(hand,board)) { return 100; } double chance = (1 - (double)Probability.choose(41-i,n)/(double)Probability.choose(47-i,n)) * 100; return chance; } public static double twoPairingUpChance(Hand hand, Hand board, int n, boolean river) { int i = 0; if (river) { i = 1; } Card[] cards = hand.getCards(); if (cards[0].getValueInt() == cards[1].getValueInt()) { return 0; } if (PocketBoardAnalyzer.twoPairedUp(hand,board)) { return 100; } else if (PocketBoardAnalyzer.pairedUp(hand,board)) { //Pocket: AQ //Board: AT3 double chance = ((double) ( //Q* Probability.choose(3,1)*Probability.choose(44-i,n-1) //QQ + Probability.choose(3,2)*Probability.choose(44-i,n-2) //A* + Probability.choose(2,1)*Probability.choose(44-i,n-1) //AA + Probability.choose(2,2)*Probability.choose(44-i,n-2) //AQ + Probability.choose(2,1)*Probability.choose(3,1)*Probability.choose(44-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else { //Pocket: AQ //Board: KT3 double chance = ((double) ( //AQ Probability.choose(3,1)*Probability.choose(3,1)*Probability.choose(44,n-2) //AA or QQ + Probability.choose(3,2)*2*Probability.choose(44,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } } public static double threeKindChance(Hand hand, Hand board, int n, boolean river) { int i = 0; if (river) { i = 1; } Card[] cards = hand.getCards(); if (PocketBoardAnalyzer.tripledUp(hand,board)) { return 100; } else if (PocketBoardAnalyzer.twoPairedUp(hand,board)) { return 0; } else if (PocketBoardAnalyzer.pairedUp(hand,board)) { //Pocket: AQ //Board: AT3 double chance = ((double) ( Probability.choose(2,1)*Probability.choose(42-i,n-1) //A* + Probability.choose(2,2)*Probability.choose(45-i,n-2) //AA + Probability.choose(3,2)*Probability.choose(44-i,n-2) //QQ + Probability.choose(2,1)*Probability.choose(3,1)*Probability.choose(44,n-2) //AQ ) / Probability.choose(47-i,n)) * 100; return chance; } else { //Pocket: AQ //Board: KT3 double chance = ((double) ( Probability.choose(3,2)*2*Probability.choose(44-i,n-2) //AA or QQ ) / Probability.choose(47-i,n)) * 100; return chance; } } public static double straightChance(Hand hand, Hand board, int n, boolean river) { int i = 0; if (river) { i = 1; } Card[] cards = hand.getCards(); if (PocketBoardAnalyzer.straightedUp(hand,board)) { return 100; } else if (PocketBoardAnalyzer.outsideStraight(hand,board)) { double chance = ((double) ( Probability.choose(8,1)*Probability.choose(39-i,n-1) + Probability.choose(8,2)*Probability.choose(39-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else if (PocketBoardAnalyzer.insideStraight(hand,board)) { double chance = ((double) ( Probability.choose(4,1)*Probability.choose(43-i,n-1) + Probability.choose(4,2)*Probability.choose(43-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else { return 0; } } public static double flushChance(Hand hand, Hand board, int n, boolean river) { int i = 0; if (river) { i = 1; } Card[] cards = hand.getCards(); if (PocketBoardAnalyzer.flushedUp(hand,board)) { return 100; } else if (PocketBoardAnalyzer.oneToFlush(hand,board)) { double chance = ((double) ( Probability.choose(9,1)*Probability.choose(38-i,n-1) + Probability.choose(9,2)*Probability.choose(38-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else if (PocketBoardAnalyzer.twoToFlush(hand,board)) { double chance = ((double) ( Probability.choose(10,2)*Probability.choose(37-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else { return 0; } } public static double straightFlushChance(Hand hand, Hand board, int n, boolean river) { int i = 0; if (river) { i = 1; } Card[] cards = hand.getCards(); if (PocketBoardAnalyzer.straightFlushedUp(hand,board)) { return 100; } else if (PocketBoardAnalyzer.outsideStraightFlush(hand,board)) { double chance = ((double) ( Probability.choose(2,1)*Probability.choose(45-i,n-1) + Probability.choose(2,2)*Probability.choose(45-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else if (PocketBoardAnalyzer.insideStraightFlush(hand,board)) { double chance = ((double) ( Probability.choose(1,1)*Probability.choose(46-i,n-1) ) / Probability.choose(47-i,n)) * 100; return chance; } else { return 0; } } public static double fullHouseChance(Hand hand, Hand board, int n, boolean river) { int i = 0; if (river) { i = 1; } Card[] cards = hand.getCards(); if (PocketBoardAnalyzer.fullHousedUp(hand,board)) { return 100; } else if (HandPossibilities.threeKindChance(hand,board,n,river) == 100) { //Pocket: AQ //Board: AA3 double chance = ((double) ( //Q* or 3* 6*Probability.choose(40-i,n-1) //PP (running pair) + 60*Probability.choose(40-i,n-2) //QQ or 33 + 6*Probability.choose(40-i,n-2) //A* + Probability.choose(40-i,n-1) //AQ or A3 + 6*Probability.choose(40-i,n-2) //Q3 + 9*Probability.choose(40-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else if (HandPossibilities.twoPairingUpChance(hand,board,n,river) == 100) { //Pocket: AQ //Board: AQ3 double chance = ((double) ( //A* or Q* 4*Probability.choose(44-i,n-1) //AA or QQ + 2*Probability.choose(40-i,n-2) //AQ + Probability.choose(40-i,n-2) //33 + 2*Probability.choose(44-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } else if (HandPossibilities.pairingUpChance(hand,board,n,river) == 100) { if (PocketBoardAnalyzer.pairOnBoard(board)) { double chance = ((double) ( Probability.choose(4,1)*Probability.choose(43-i,n-1) //full house + Probability.choose(2,2)*2*Probability.choose(45-i,n-2) //4 of a kind + Probability.choose(3,2)*Probability.choose(44-i,n-2) //blanks full of your pair ) / Probability.choose(47-i,n)) * 100; return chance; } else { double chance = ((double) ( Probability.choose(2,1)*Probability.choose(9,1)*Probability.choose(45-i,n-2) //favorable full house + Probability.choose(2,2)*Probability.choose(45-i,n-2) //favorable 4 of a kind + Probability.choose(3,2)*3*Probability.choose(44-i,n-2) ) / Probability.choose(47-i,n)) * 100; return chance; } } else { if (PocketBoardAnalyzer.trippleOnBoard(board)) { return 0; } else { return 0; } } } public static void main(String[] args) { Hand hand = new Hand(); hand.addCard("HA"); hand.addCard("C4"); Hand board = new Hand(); board.addCard("HA"); board.addCard("HQ"); board.addCard("HT"); //board.addCard("C2"); //board.addCard("H2"); System.out.println("My Hand: "+hand); System.out.println("Board: "+board); // System.out.println("Pair of my kind? -" + PocketBoardAnalyzer.pairedUp(hand,board)); // System.out.println("Two pair of my kind? -" + PocketBoardAnalyzer.twoPairedUp(hand,board)); // System.out.println("Three of a kind of my kind? -" + PocketBoardAnalyzer.tripledUp(hand,board)); // System.out.println("Full house? -" + PocketBoardAnalyzer.fullHousedUp(hand,board)); // System.out.println("Four of a kind? -" + PocketBoardAnalyzer.quadedUp(hand,board)); // System.out.println("Inside straight chance? -" + PocketBoardAnalyzer.insideStraight(hand,board)); // System.out.println("Outside straight chance? -" + PocketBoardAnalyzer.outsideStraight(hand,board)); // System.out.println("Straight? -" + PocketBoardAnalyzer.straightedUp(hand,board)); // System.out.println("Two more to flush? -" + PocketBoardAnalyzer.twoToFlush(hand,board)); // System.out.println("One more to flush? -" + PocketBoardAnalyzer.oneToFlush(hand,board)); // System.out.println("Flush? -" + PocketBoardAnalyzer.flushedUp(hand,board)); // System.out.println("Inside straight flush? -" + PocketBoardAnalyzer.insideStraightFlush(hand,board)); // System.out.println("Outside straight flush? -" + PocketBoardAnalyzer.outsideStraightFlush(hand,board)); // System.out.println("Straight flush? -" + PocketBoardAnalyzer.straightFlushedUp(hand,board)); System.out.println("Chance to pair up - " + pairingUpChance(hand,board,2,false)); System.out.println("twoPairingUpChance - " + twoPairingUpChance(hand,board,2,false)); //System.out.println("threeKindChance - " + threeKindChance(hand,board,2,false)); System.out.println("straightChance - " + straightChance(hand,board,2,false)); System.out.println("flushChance - " + flushChance(hand,board,2,false)); System.out.println("straightFlushChance - " + straightFlushChance(hand,board,2,false)); System.out.println("fullHouseChance - " + fullHouseChance(hand,board,2,false)); } }