poker odds

Hi, i found some source code online for a holdem poker odds calculator.

i had a look at the code, and tried to copy and compile it. It compiles, but doesn't give the answer i was expecting! bascially it's for a java appletts which you can see here:

http://www.jbridge.net/jimmy/holdem_sim.htm

As you can see, a % probability shows in the top left of the applet. What i need is the same code, so that when i supply hard-coded values for the number of players, the cards etc, it will print to the console the % probabilty. I have literally tried to work out the code for two days without any luck. I was wondering if someone who knows abit more about java could take a peak.

here is the code

poker.java: contains what i am after basically (the evaluate function i think is the most important)

package cardgame;

import java.util.HashSet;

import java.util.Set;

import java.util.logging.Logger;

// Referenced classes of package cardgame:

//Card

publicabstractclass Poker

{

publicstaticfinalint HIGH_CARD = 0;

publicstaticfinalint PAIR = 1;

publicstaticfinalint TWO_PAIRS = 2;

publicstaticfinalint THREE_OF_A_KIND = 3;

publicstaticfinalint STRAIGHT = 4;

publicstaticfinalint FLUSH = 5;

publicstaticfinalint FULL_HOUSE = 6;

publicstaticfinalint FOUR_OF_A_KIND = 7;

publicstaticfinalint STRAIGHT_FLUSH = 8;

publicstaticfinalint WIN = 0;

publicstaticfinalint TIE = 1;

publicstaticfinalint LOSE = 2;

protectedboolean cardTable[][];

protectedint suitSum[];

protectedint rankSum[];

protectedint event[];

protectedint totalEvent;

protectedint rankList[];

protectedint cardNum;

protectedint maxSimulation;

protectedint reportInterval;

protectedboolean stopSimulation;

private Set cardSet;

privatestatic Logger logger;

privatestaticfinalint effectiveValues[] ={

5, 4, 3, 3, 1, 5, 2, 2, 1

};

privatestatic String handType[] ={

"High Card","One Pair","Two Pairs","Three of A Kind","Straight","Flush","Full House","Four of A Kind","Straight Flush"

};

publicstaticclass HandValueimplements Comparable

{

public String toString()

{

StringBuffer buf =new StringBuffer(Poker.handType[type]);

for(int i = 0; i < Poker.effectiveValues[type]; i++)

buf.append(' ').append(Card.rank2text(values[i]));

return buf.toString();

}

publicint compareTo(Object obj)

{

HandValue hv = (HandValue)obj;

if(type != hv.type)

return type - hv.type;

for(int i = 0; i < Poker.effectiveValues[type]; i++)

if(values[i] != hv.values[i])

return values[i] - hv.values[i];

return 0;

}

protectedint type;

protectedint values[];

public HandValue()

{

values =newint[5];

}

}

public Poker(int numCard, Card deck[])

{

cardTable =newboolean[4][13];

suitSum =newint[4];

rankSum =newint[13];

event =newint[3];

maxSimulation = 0x7fffffff;

reportInterval = 0x186a0;

cardSet =new HashSet();

rankList =newint[cardNum = numCard];

for(int i = 0; i < deck.length; i++)

cardSet.add(deck[i]);

}

publicabstractvoid startSimulation(boolean flag);

protectedabstractvoid report();

protectedabstractvoid finished();

publicvoid stopSimulation()

{

stopSimulation =true;

}

publicvoid maxSimulation(int ms)

{

maxSimulation = ms;

}

publicint maxSimulation()

{

return maxSimulation;

}

publicvoid reportInterval(int ri)

{

reportInterval = ri;

}

publicint reportInterval()

{

return reportInterval;

}

publicint[] getEvent()

{

return event;

}

publicvoid clearEvent()

{

event[0] = event[1] = event[2] = totalEvent = 0;

}

publicvoid getEventProbability(double prob[])

{

prob[0] = (double)event[0] / (double)totalEvent;

prob[1] = (double)event[1] / (double)totalEvent;

prob[2] = 1.0D - prob[0] - prob[1];

}

protectedvoid setCards(Card cards[])

{

for(int i = 0; i < cards.length; i++)

setCard(cards[i]);

}

protectedvoid setCard(Card card)

{

cardTable[card.suit()][card.rank()] =true;

suitSum[card.suit()]++;

rankSum[card.rank()]++;

}

protectedvoid removeCards(Card cards[])

{

for(int i = 0; i < cards.length; i++)

removeCard(cards[i]);

}

protectedvoid removeCard(Card card)

{

cardTable[card.suit()][card.rank()] =false;

suitSum[card.suit()]--;

rankSum[card.rank()]--;

}

protectedvoid holdCards(Card cards[])

{

for(int i = 0; i < cards.length; i++)

holdCard(cards[i]);

}

protectedvoid holdCard(Card card)

{

if(cardSet.remove(card))

logger.fine("Card hold: " + card);

else

logger.warning("Card not in deck: " + card);

}

protectedvoid unHoldCards(Card cards[])

{

for(int i = 0; i < cards.length; i++)

unHoldCard(cards[i]);

}

protectedvoid unHoldCard(Card card)

{

if(cardSet.add(card))

logger.fine("Card unhold: " + card);

else

logger.warning("Card already in deck: " + card);

}

public Card[] getRemainingCards()

{

Card remain[] =new Card[cardSet.size()];

getRemainingCards(remain);

return remain;

}

publicvoid getRemainingCards(Card remain[])

{

cardSet.toArray(remain);

}

protectedint evaluate(HandValue hand)

{

int flushSuit = -1;

for(int i = 0; i < 4; i++)

{

if(suitSum[i] < 5)

continue;

flushSuit = i;

break;

}

int straight = 0;

int pair = 0;

int three = 0;

int four = 0;

int rankCount = 0;

for(int i = 12; i >= 0; i--)

{

switch(rankSum[i])

{

case 4:// '\004'

four++;

straight++;

rankList[rankCount++] = i;

break;

case 3:// '\003'

three++;

straight++;

rankList[rankCount++] = i;

break;

case 2:// '\002'

pair++;

straight++;

rankList[rankCount++] = i;

break;

case 1:// '\001'

straight++;

rankList[rankCount++] = i;

break;

default:

if(straight < 5)

straight = 0;

break;

}

if(i == 0 && straight == 4 && rankSum[12] > 0)

straight++;

}

if(straight >= 5 && flushSuit >= 0)

{

int straightflush = 0;

int highest = rankList[0];

int lowest = rankList[rankCount - 1];

for(int i = highest; i >= lowest && straightflush < 5; i--)

{

if(cardTable[flushSuit][i])

{

if(++straightflush == 1)

highest = i;

}else

{

straightflush = 0;

}

if(i == 0 && straightflush == 4 && cardTable[flushSuit][12])

straightflush++;

}

if(straightflush >= 5)

{

hand.type = 8;

hand.values[0] = highest;

return hand.type;

}

}

if(four > 0)

{

hand.type = 7;

for(int i = 0; i < rankCount; i++)

{

if(rankSum[rankList[i]] == 4)

{

hand.values[0] = rankList[i];

if(i == 0)

hand.values[1] = rankList[1];

break;

}

if(i == 0)

hand.values[1] = rankList[i];

}

}else

if(three > 1 || three > 0 && pair > 0)

{

hand.type = 6;

boolean threeDone =false;

boolean pairDone =false;

for(int i = 0; i < rankCount; i++)

{

if(rankSum[rankList[i]] == 3)

{

if(threeDone)

{

hand.values[1] = rankList[i];

break;

}

hand.values[0] = rankList[i];

if(pairDone)

break;

continue;

}

if(rankSum[rankList[i]] != 2 || pairDone)

continue;

hand.values[1] = rankList[i];

if(threeDone)

break;

pairDone =true;

}

}else

if(flushSuit >= 0)

{

hand.type = 5;

int copied = 0;

for(int rankId = 0; copied < 5; rankId++)

if(cardTable[flushSuit][rankList[rankId]])

hand.values[copied++] = rankList[rankId];

}else

if(straight >= 5)

{

hand.type = 4;

hand.values[0] = rankList[rankCount - 3];

for(int i = rankCount - 4; i >= 0; i--)

{

if(rankList[i] - hand.values[0] != 1)

break;

hand.values[0] = rankList[i];

}

}else

if(three > 0)

{

hand.type = 3;

int highCard = 0;

boolean threeFilled =false;

for(int i = 0; i < rankCount; i++)

{

if(rankSum[rankList[i]] == 3)

{

hand.values[0] = rankList[i];

if(highCard == 2)

break;

threeFilled =true;

continue;

}

if(highCard >= 2)

continue;

hand.values[++highCard] = rankList[i];

if(highCard == 2 && threeFilled)

break;

}

}else

if(pair > 1)

{

hand.type = 2;

int pairFilled = 0;

boolean lastFilled =false;

for(int i = 0; i < rankCount; i++)

{

if(rankSum[rankList[i]] == 2)

{

if(pairFilled < 2)

{

hand.values[pairFilled++] = rankList[i];

if(pairFilled == 2 && lastFilled)

break;

continue;

}

hand.values[2] = rankList[i];

break;

}

if(lastFilled)

continue;

hand.values[2] = rankList[i];

if(pairFilled == 2)

break;

lastFilled =true;

}

}else

if(pair > 0)

{

hand.type = 1;

int highcard = 0;

boolean pairFound =false;

for(int i = 0; i < rankCount; i++)

{

if(rankSum[rankList[i]] == 2)

{

hand.values[0] = rankList[i];

if(highcard == 3)

break;

pairFound =true;

continue;

}

if(highcard >= 3)

continue;

hand.values[++highcard] = rankList[i];

if(highcard == 3 && pairFound)

break;

}

}else

{

hand.type = 0;

for(int i = 0; i < 5; i++)

hand.values[i] = rankList[i];

}

//System.out.println("ht: " + hand.type);

return hand.type;

}

publicint evaluateHand(Card hole[], HandValue hand)

{

setCards(hole);

int val = evaluate(hand);

removeCards(hole);

return val;

}

protectedint registerEvent(HandValue my, HandValue op)

{

//System.out.println(event);

int comp = my.compareTo(op);

int e = 1;

if(comp < 0)

e = 2;

else

if(comp > 0)

e = 0;

event[e]++;

totalEvent++;

return e;

}

protectedvoid registerEvent(int e)

{

event[e]++;

totalEvent++;

}

static

{

logger = Logger.getLogger(cardgame.Poker.class.getName());

}

}

oneholdem.java i think contains the functions which call the gui:

// Decompiled by DJ v3.8.8.85 Copyright 2005 Atanas Neshkov Date: 22/09/2005 15:07:13

// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!

// Decompiler options: packimports(3)

// Source File Name:OneHoldEm.java

package view;

import cardgame.*;

import java.awt.*;

import java.awt.event.*;

import java.io.File;

import java.io.PrintStream;

import java.text.DecimalFormat;

import java.text.NumberFormat;

import javax.swing.*;

import javax.swing.border.TitledBorder;

// Referenced classes of package view:

//BoardListener, Simculator, CardHolder, CardBoard,

//SpringUtilities, CardView

publicclass OneHoldEmextends JPanel

implements BoardListener, Simculator

{

privatestaticfinallong serialVersionUID = 0xb3551d00c69d3aa0L;

private CardBoard board;

private CardHolder holder[];

private JTextField winScore;

private JTextField tieScore;

private JTextField losScore;

private JTextField potSize;

private JTextField unitSize;

private JTextField betSize;

private JButton resetButton;

private JButton simulButton;

private JSpinner pNumSpinner;

private JComboBox sNumBox;

private JProgressBar progressBar;

private JButton stopButton;

private CardLayout ctrlLayout;

private JPanel ctrlPanel;

privateint inHolder;

privatelong startTime;

private ExpectedWin expectedWin;

privatedouble pot;

private Card deck[];

private HoldEm holdEm;

private String progressView;

private String controlView;

private NumberFormat proForm;

private NumberFormat betForm;

private ActionListener cardReturner;

public OneHoldEm(Color bkground, Font defFont)

throws Exception

{

holder =new CardHolder[7];

winScore =new JTextField(8);

tieScore =new JTextField(8);

losScore =new JTextField(8);

potSize =new JTextField("0.00");

unitSize =new JTextField("0.05");

betSize =new JTextField();

resetButton =new JButton("Reset");

simulButton =new JButton("Simulate");

pNumSpinner =new JSpinner(new SpinnerNumberModel(2, 2, 10, 1));

sNumBox =new JComboBox(new String[]{

"Unlimited","100,000","1,000,000","10,000,000"

});

progressBar =new JProgressBar();

stopButton =new JButton("Stop");

ctrlLayout =new CardLayout();

ctrlPanel =new JPanel(ctrlLayout);

expectedWin =new ExpectedWin(0.050000000000000003D);

deck = Card.createDeck();

holdEm =new HoldEm(deck){

protectedvoid report()

{

System.out.println(": " + event[0] +"\t" + event[1] +"\t" + event[2] +"\t" + totalEvent);

double winProb = (double)event[0] / (double)totalEvent;

double tieProb = (double)event[1] / (double)totalEvent;

System.out.println("prob: " + winProb);

winScore.setText(proForm.format(winProb));

tieScore.setText(proForm.format(tieProb));

losScore.setText(proForm.format((float)event[2] / (float)totalEvent));

int playerNum = ((Integer)pNumSpinner.getValue()).intValue();

expectedWin.setTable(pot, winProb, tieProb, playerNum);

double breakEven = expectedWin.breakEven();

System.out.println("Breakeven size: " + breakEven);

if(breakEven < 0.0D)

betSize.setText("Raise");

else

if(breakEven < expectedWin.unitBet())

betSize.setText("Fold");

else

betSize.setText("less than " + betForm.format(breakEven));

if(maxSimulation > 0)

progressBar.setValue(totalEvent);

//else

//progressBar.setString(totalEvent);

}

protectedvoid finished()

{

System.out.println("yo");

report();

long endTime = System.currentTimeMillis();

System.out.println("endTime - startTime");

ctrlLayout.show(ctrlPanel, controlView);

}

};

progressView ="progress";

controlView ="control";

proForm = NumberFormat.getPercentInstance();

betForm = NumberFormat.getInstance();

cardReturner =new ActionListener(){

publicvoid actionPerformed(ActionEvent e)

{

returnCard((CardHolder)e.getSource());

}

};

board =new CardBoard(deck, true, bkground);

board.flipMode(-1);

board.addBoardListener(this);

for(int i = 0; i < holder.length; i++)

{

holder[i] =new CardHolder();

holder[i].addActionListener(cardReturner);

}

((DecimalFormat)proForm).applyPattern("0.00%");

((DecimalFormat)betForm).applyPattern("0.00");

if(defFont !=null)

{

resetButton.setFont(defFont);

simulButton.setFont(defFont);

stopButton.setFont(defFont);

}

buildGUI();

}

privatevoid buildGUI()

{

setBorder(new TitledBorder("Hold'Em Odds Simulator"));

resetButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e)

{

for(int i = 0; i < holder.length; i++)

returnCard(holder[i]);

winScore.setText("ert");

tieScore.setText("");

losScore.setText("");

potSize.setText("0.00");

pot = 0.0D;

}

});

simulButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e)

{

simulate();

}

});

stopButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e)

{

holdEm.stopSimulation();

}

});

unitSize.addFocusListener(new FocusListener(){

publicvoid focusGained(FocusEvent focusevent)

{

}

publicvoid focusLost(FocusEvent arg0)

{

try

{

double newUnit = Double.parseDouble(unitSize.getText());

if(newUnit > 0.0D)

{

expectedWin.unitBet(newUnit);

System.out.println("New bet unit: " + newUnit);

return;

}

}

catch(NumberFormatException numberformatexception){}

unitSize.setText((new StringBuffer(String.valueOf(expectedWin.unitBet()))).toString());

}

});

potSize.addFocusListener(new FocusListener(){

publicvoid focusGained(FocusEvent focusevent)

{

}

publicvoid focusLost(FocusEvent arg0)

{

try

{

double newPot = Double.parseDouble(potSize.getText());

if(newPot >= 0.0D)

{

pot = newPot;

System.out.println("New pot size: " + newPot);

return;

}

}

catch(NumberFormatException numberformatexception){}

potSize.setText((new StringBuffer(String.valueOf(pot))).toString());

}

});

JPanel holePanel =new JPanel(new FlowLayout(0, 1, 1));

holePanel.setBorder(new TitledBorder("Hole"));

holePanel.add(holder[0]);

holePanel.add(holder[1]);

JPanel commPanel =new JPanel(new FlowLayout(0, 1, 1));

commPanel.setBorder(new TitledBorder("Community"));

commPanel.add(holder[2]);

commPanel.add(holder[3]);

commPanel.add(holder[4]);

commPanel.add(holder[5]);

commPanel.add(holder[6]);

Box butBar = Box.createHorizontalBox();

butBar.add(Box.createHorizontalGlue());

butBar.add(resetButton);

butBar.add(Box.createHorizontalGlue());

butBar.add(simulButton);

butBar.add(Box.createHorizontalGlue());

JPanel optBox =new JPanel(new SpringLayout());

optBox.add(new JLabel("# of simulation", 0));

optBox.add(new JLabel("players", 0));

optBox.add(sNumBox);

optBox.add(pNumSpinner);

SpringUtilities.makeCompactGrid(optBox, 2, 2, 0, 0, 0, 0);

JPanel ctrlBox =new JPanel(new BorderLayout());

ctrlBox.add(optBox,"North");

ctrlBox.add(butBar,"Center");

Box proPanel = Box.createVerticalBox();

proPanel.add(Box.createGlue());

proPanel.add(progressBar);

proPanel.add(Box.createVerticalStrut(3));

proPanel.add(stopButton);

stopButton.setAlignmentX(0.5F);

proPanel.add(Box.createVerticalStrut(3));

ctrlPanel.add(ctrlBox, controlView);

ctrlPanel.add(proPanel, progressView);

JPanel scorePanel =new JPanel(new SpringLayout());

scorePanel.add(new JLabel("Win: "));

scorePanel.add(winScore);

scorePanel.add(new JLabel("Tie: "));

scorePanel.add(tieScore);

scorePanel.add(new JLabel("Lose: "));

scorePanel.add(losScore);

scorePanel.add(new JLabel("Pot: "));

scorePanel.add(potSize);

scorePanel.add(new JLabel("Unit: "));

scorePanel.add(unitSize);

scorePanel.add(new JLabel("Bet? "));

scorePanel.add(betSize);

SpringUtilities.makeCompactGrid(scorePanel, 2, 6, 1, 1, 1, 1);

JPanel botPanel =new JPanel(new BorderLayout());

botPanel.add(holePanel,"West");

botPanel.add(commPanel,"East");

botPanel.add(ctrlPanel,"Center");

setLayout(new BorderLayout());

add(scorePanel,"North");

add(board,"Center");

add(botPanel,"South");

}

publicvoid stop()

{

holdEm.stopSimulation();

}

protectedvoid simulate()

{

if(!checkHolder())

return;

holdEm.clearTable();

holdEm.clearEvent();

holdEm.setPlayerNum(((Integer)pNumSpinner.getValue()).intValue());

int max = -1;

switch(sNumBox.getSelectedIndex())

{

case 1:// '\001'

max = 0x186a0;

break;

case 2:// '\002'

max = 0xf4240;

break;

case 3:// '\003'

max = 0x989680;

break;

default:

max = -1;

break;

}

holdEm.maxSimulation(max);

if(max > 0)

{

progressBar.setMaximum(max);

progressBar.setIndeterminate(false);

progressBar.setStringPainted(false);

}else

{

progressBar.setIndeterminate(true);

progressBar.setStringPainted(true);

}

holdEm.setHole(holder[0].getCard(), holder[1].getCard());

if(inHolder > 2)

holdEm.setFlop(holder[2].getCard(), holder[3].getCard(), holder[4].getCard());

if(inHolder > 5)

holdEm.setTurn(holder[5].getCard());

if(inHolder > 6)

holdEm.setRiver(holder[6].getCard());

ctrlLayout.show(ctrlPanel, progressView);

startTime = System.currentTimeMillis();

holdEm.startSimulation(false);

}

privateboolean checkHolder()

{

if(holder[0].isEmpty() || holder[1].isEmpty())

{

JOptionPane.showMessageDialog(this,"Need 2 hole cards");

returnfalse;

}

if(inHolder > 2 && inHolder < 7)

switch(inHolder)

{

case 5:// '\005'

if(!holder[5].isEmpty() || !holder[6].isEmpty())

{

JOptionPane.showMessageDialog(this,"Need 3 flop cards");

returnfalse;

}

break;

case 6:// '\006'

if(!holder[6].isEmpty())

{

JOptionPane.showMessageDialog(this,"Need turn card");

returnfalse;

}

break;

default:

JOptionPane.showMessageDialog(this,"Need 3 flop cards");

returnfalse;

}

returntrue;

}

publicvoid cardFlipped(CardBoard board, Card card,boolean faceUp)

{

if(!faceUp)

{

if(inHolder >= holder.length)

{

System.out.println("Holder full");

board.flip(card, 1);

return;

}

for(int i = 0; i < holder.length; i++)

{

if(!holder[i].isEmpty())

continue;

try

{

holder[i].setCard(card);

}

catch(Exception e)

{

e.printStackTrace();

}

inHolder++;

System.out.println(card +" put in holder " + i);

break;

}

}

}

privatevoid returnCard(CardHolder holder)

{

if(!holder.isEmpty())

{

Card c = holder.removeCard();

inHolder--;

board.flip(c, 1);

System.out.println(c +" removed from holder");

}

}

publicstaticvoid main(String args[])

throws Exception

{

File cimg[] ={

new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),

new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),

new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),

new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),

new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),new File("cards.png"),

new File("cards.png"),new File("cards.png")

};

CardView.loadIcons(cimg,null);

Color wizYellow =new Color(206, 231, 245);

UIManager.put("Panel.background", wizYellow);

Font defFont =new Font("Arial", 0, 12);

UIManager.put("TitledBorder.font", defFont);

UIManager.put("Label.font", defFont);

UIManager.put("ComboBox.font", defFont);

JFrame frame =new JFrame("One hole table test");

frame.setDefaultCloseOperation(3);

OneHoldEm ohe =new OneHoldEm(null, defFont);

frame.getContentPane().add(ohe,"Center");

frame.pack();

frame.setResizable(false);

frame.setLocationRelativeTo(null);

frame.show();

}

}

holdem extends poker , and cntains a startsimulatoin method which i think is really important:

// Decompiled by DJ v3.8.8.85 Copyright 2005 Atanas Neshkov Date: 22/09/2005 15:07:12

// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!

// Decompiler options: packimports(3)

// Source File Name:HoldEm.java

package cardgame;

// Referenced classes of package cardgame:

//Poker, Card, Dealer

publicclass HoldEmextends Poker

{

publicstaticfinalint FLOP = 3;

publicstaticfinalint TURN = 4;

publicstaticfinalint RIVER = 5;

publicstaticfinalint MAX_PLAYERS = 10;

private Card holes[][];

private Card flop[];

private Card turn;

private Card river;

privateint playerNum;

privateint needCommunity;

private Poker.HandValue myValue;

private Poker.HandValue opValue;

private Dealer dealer;

public HoldEm(Card deck[])

{

super(7, deck);

holes =new Card[10][2];

flop =new Card[3];

playerNum = 2;

needCommunity = 5;

myValue =new Poker.HandValue();

opValue =new Poker.HandValue();

dealer =new Dealer();

}

publicvoid setPlayerNum(int pn)

{

playerNum = pn;

}

publicvoid setHole(Card c1, Card c2)

{

holes[0][0] = c1;

holes[0][1] = c2;

holdCards(holes[0]);

}

publicvoid setHole(Card h[])

{

setHole(h[0], h[1]);

}

publicvoid setFlop(Card c1, Card c2, Card c3)

{

flop[0] = c1;

flop[1] = c2;

flop[2] = c3;

setCards(flop);

holdCards(flop);

needCommunity -= 3;

}

publicvoid setFlop(Card f[])

{

setFlop(f[0], f[1], f[2]);

}

publicvoid setTurn(Card c)

{

setCard(turn = c);

holdCard(c);

needCommunity--;

}

publicvoid setRiver(Card c)

{

setCard(river = c);

holdCard(c);

needCommunity--;

}

publicvoid clearTable()

{

if(flop[0] !=null)

{

removeCards(flop);

unHoldCards(flop);

}

if(turn !=null)

{

removeCard(turn);

unHoldCard(turn);

}

if(river !=null)

{

removeCard(river);

unHoldCard(river);

}

if(holes[0][0] !=null)

unHoldCards(holes[0]);

holes[0][0] = holes[0][1] = turn = river =null;

flop[0] = flop[1] = flop[2] =null;

needCommunity = 5;

}

publicvoid startSimulation(boolean block)

{

stopSimulation =false;

dealer.resetShoe(getRemainingCards(),false);

(new Thread(){

publicvoid run()

{

int simCount;

int reportCount;

int cardsPerRound;

clearEvent();

simCount = maxSimulation;

reportCount = reportInterval;

cardsPerRound = (playerNum - 1 << 1) + needCommunity;

_L2:

label0:

{

if(dealer.getRemainingSize() < cardsPerRound)

dealer.resetShoe(true);

fillCommunity(needCommunity);

evaluateHand(holes[0], myValue);

int result = 0;

for(int i = 1; i < playerNum; i++)

{

dealer.deal(holes[i]);

if(result != 2)

{

evaluateHand(holes[i], opValue);

int compare = myValue.compareTo(opValue);

if(compare == 0)

result = 1;

else

if(compare < 0)

result = 2;

}

}

registerEvent(result);

if(--reportCount <= 0)

{

report();

reportCount = reportInterval;

}

clearCommunity(needCommunity);

synchronized(HoldEm.this)

{

if(simCount > 0 && --simCount == 0)

stopSimulation =true;

if(!stopSimulation)

break label0;

}

//break; /* Loop/switch isn't completed */

}

holdem2;

JVM INSTR monitorexit ;

if(true)goto _L2;elsegoto _L1

_L1:

synchronized(HoldEm.this)

{

notifyAll();

}

finished();

return;

}

privatevoid clearCommunity(int needMoreCards)

{

if(needMoreCards > 0)

{

removeCard(river);

river =null;

}

if(needMoreCards > 1)

{

removeCard(turn);

turn =null;

}

if(needMoreCards > 2)

{

removeCards(flop);

flop[0] = flop[1] = flop[2] =null;

}

}

privatevoid fillCommunity(int needMoreCards)

{

if(needMoreCards > 0)

{

river = dealer.deal();

setCard(river);

}

if(needMoreCards > 1)

{

turn = dealer.deal();

setCard(turn);

}

if(needMoreCards > 2)

{

dealer.deal(flop);

setCards(flop);

}

}

// {

//super();

// }

}).start();

if(block)

synchronized(this)

{

try

{

wait();

}

catch(InterruptedException interruptedexception){}

}

}

protectedvoid report()

{

}

protectedvoid finished()

{

}

}

there are some more classes, but i don't think they are necessary in working it out. whoever takes the time to help me implement the simplest version of this get's all my duke dollars for their efforts! cheers.

[67491 byte] By [davidstummera] at [2007-10-2 0:48:17]
# 1

here are some addiotonal files which may be needed

package cardgame;

public class Card

implements Comparable

{

private int suit;

private int rank;

private int index;

public Card(int s, int r)

{

suit = s;

rank = r;

index = s * 13 + r;

}

public int suit()

{

return suit;

}

public String suitString()

{

return suitString[suit];

}

public int rank()

{

return rank;

}

public String rankString()

{

return rankString[rank];

}

public int index()

{

return index;

}

public boolean isPair(Card c)

{

return rank == c.rank;

}

public boolean isSuited(Card c)

{

return suit == c.suit;

}

public String toString()

{

return suitString[suit] + rankString[rank];

}

public static Card createCard(String name)

{

if(name != null && name.length() == 2)

return new Card(getSuit(name.charAt(0)), getRank(name.charAt(1)));

else

return null;

}

public static Card[] createDeck()

{

Card deck[] = new Card[52];

int i = 0;

int cardCount = 0;

for(; i < 4; i++)

{

for(int j = 0; j < 13; j++)

deck[cardCount++] = new Card(i, j);

}

return deck;

}

public static boolean isPair(Card c1, Card c2)

{

return c1.rank == c2.rank;

}

public static boolean isSuited(Card c1, Card c2)

{

return c1.suit == c2.suit;

}

public static String suit2text(int suit)

{

return suitString[suit];

}

public static String rank2text(int rank)

{

return rankString[rank];

}

public static int cardIndex(String name)

{

if(name != null && name.length() == 2)

return getSuit(name.charAt(0)) * 13 + getRank(name.charAt(1));

else

return -1;

}

private static int getSuit(char sc)

{

switch(sc)

{

case 83: // 'S'

case 115: // 's'

return 0;

case 67: // 'C'

case 99: // 'c'

return 1;

case 68: // 'D'

case 100: // 'd'

return 2;

case 72: // 'H'

case 104: // 'h'

return 3;

}

return -1;

}

private static int getRank(char rc)

{

switch(rc)

{

case 50: // '2'

return 0;

case 51: // '3'

return 1;

case 52: // '4'

return 2;

case 53: // '5'

return 3;

case 54: // '6'

return 4;

case 55: // '7'

return 5;

case 56: // '8'

return 6;

case 57: // '9'

return 7;

case 84: // 'T'

case 116: // 't'

return 8;

case 74: // 'J'

case 106: // 'j'

return 9;

case 81: // 'Q'

case 113: // 'q'

return 10;

case 75: // 'K'

case 107: // 'k'

return 11;

case 65: // 'A'

case 97: // 'a'

return 12;

}

return -1;

}

public boolean equals(Object o)

{

if(o instanceof Card)

return index == ((Card)o).index;

else

return false;

}

public int hashCode()

{

return toString().hashCode();

}

public int compareTo(Object o)

{

return index - ((Card)o).index;

}

public static final int SPADE = 0;

public static final int CLUB = 1;

public static final int DIAMOND = 2;

public static final int HEART = 3;

public static final int TWO = 0;

public static final int THREE = 1;

public static final int FOUR = 2;

public static final int FIVE = 3;

public static final int SIX = 4;

public static final int SEVEN = 5;

public static final int EIGHT = 6;

public static final int NINE = 7;

public static final int TEN = 8;

public static final int JACK = 9;

public static final int QUEEN = 10;

public static final int KING = 11;

public static final int ACE = 12;

private static String suitString[] = {

"S", "C", "D", "H"

};

private static String rankString[] = {

"2", "3", "4", "5", "6", "7", "8", "9", "T", "J",

"Q", "K", "A"

};

private int suit;

private int rank;

private int index;

}

dealer:package cardgame;

import java.io.PrintStream;

import java.util.Arrays;

import java.util.Random;

// Referenced classes of package cardgame:

//Card

public class Dealer

{

private Card shoe[];

private int dealt;

private Random random;

public Dealer()

{

random = new Random();

}

public int getShoeSize()

{

return shoe.length;

}

public int getRemainingSize()

{

return shoe.length - dealt;

}

public void resetShoe(Card deck[], boolean shuffle)

{

shoe = deck;

resetShoe(shuffle);

}

public void resetShoe(boolean shuffle)

{

dealt = 0;

if(shuffle)

shuffle();

}

private void shuffle()

{

if(shoe == null)

return;

for(int i = shoe.length - 1; i > 1; i--)

{

int swap = random.nextInt(i);

Card sc = shoe[swap];

shoe[swap] = shoe[i];

shoe[i] = sc;

}

}

public void sortShoe()

{

Arrays.sort(shoe);

}

public static void sortDeck(Card deck[])

{

Arrays.sort(deck);

}

public boolean deal(Card holder[])

{

if(shoe.length - holder.length < 0)

{

System.err.println("Not enough cards.");

return false;

}

for(int i = 0; i < holder.length;)

{

holder[i] = shoe[dealt];

i++;

dealt++;

}

return true;

}

public Card deal()

{

if(shoe.length == 0)

{

System.err.println("Not enough cards.");

return null;

} else

{

return shoe[dealt++];

}

}

}

package view;

import cardgame.Card;

import java.awt.Color;

import java.awt.Insets;

import javax.swing.*;

import javax.swing.border.Border;

// Referenced classes of package view:

//CardView

public class CardHolder extends JButton

{

public CardHolder(boolean noborder, Color defbk)

{

if(noborder)

setBorder(emptyBorder);

if(defbk != null)

setBackground(defbk);

if(empty != null)

setMargin(empty);

}

public CardHolder()

{

this(false, null);

}

public CardHolder(Card c, boolean noborder, Color defbk)

throws Exception

{

this(noborder, defbk);

setCard(c);

}

public CardHolder(Card c)

throws Exception

{

this();

setCard(c);

}

public Card getCard()

{

return card;

}

public void setCard(Card c)

throws Exception

{

card = c;

setIcon(CardView.getIcon(c));

setMargin(noEdge);

if(empty == null)

{

Icon cardIcon = CardView.getIcon(c);

int h = cardIcon.getIconHeight() >> 1;

int w = cardIcon.getIconWidth() >> 1;

empty = new Insets(h, w, h, w);

}

}

public Card removeCard()

{

setIcon(null);

setMargin(empty);

Card c = card;

card = null;

return c;

}

public boolean isEmpty()

{

return card == null;

}

private static final long serialVersionUID = 0x813e3a79e1b09158L;

private static Insets empty;

private static Insets noEdge = new Insets(0, 0, 0, 0);

private static Border emptyBorder = BorderFactory.createEmptyBorder();

private Card card;

}

cheers

davidstummera at 2007-7-15 17:58:23 > top of Java-index,Other Topics,Algorithms...
# 2
Why not contact the author?
prometheuzza at 2007-7-15 17:58:23 > top of Java-index,Other Topics,Algorithms...
# 3
because i decompiled his applett..hahno but serisouly,the author posted a few posts down in the algorothms forum, under a similar title to mine. as you can see, i have had no replies.
davidstummera at 2007-7-15 17:58:23 > top of Java-index,Other Topics,Algorithms...
# 4
> the author posted a few posts down in the algorothms> forum, under a similar title to mine. as you can see,> i have had no replies.I mean, e-mail the guy. His e-mail address is in his profile.
prometheuzza at 2007-7-15 17:58:23 > top of Java-index,Other Topics,Algorithms...