Combinations of integers

Hello is there anyone there who can help me? I am writing a program that evaluates poker hands. I need a way of creating all 2 card combinations from the list of all cards not yet dealt.

I have 4 arrays that store the undealt cards off each suit. I now need to search one of the arrays and find the first instance of an undealt card and fix this card as card 1. I then want to recursively search the rest of this array and the 3 other arrays each time returning the values of the cards not yet dealt. I have tried a few methods but either can only print out different pairs and not different combinations or i get a StackOverFlowError.

below is the code I have currently.

publicvoid selectCards(){

//p = new PokerHand();

added = 0;

//fix first card

while(added == 0){

for(int i=0;i<tothearts.length;i++){//tothearts is the array containin the hearts

if(tothearts[i] == 1){

PokerCard c1 =new PokerCard(i,PokerCard.HEARTS);//create an instance of a card with rank i & suit

p.addCard(c1);

tothearts[i] = 0;//remove this card so that duplicate cards arent included

added++;

break;

}

}

}

while(added >= 1 && added <=2){

for(int i=0;i<tothearts.length;i++){//tothearts is the array containin the hearts

if(tothearts[i] == 1){

PokerCard c1 =new PokerCard(i,PokerCard.HEARTS);//create an instance of a card with rank i & suit

p.addCard(c1);

tothearts[i] = 0;//remove this card so that duplicate cards arent included

added++;

System.out.println("Hand = "+p);

p.removeCard(p.getHand().size()-1);

break;

}

}

}

selectCards();

}

The above code is only for one suit eventually i want to be able to do it for all four suits

here is my output:

My hand = 7c qd ah 5h jc 8c 9c

Opponents hand = ? ? ah 5h jc 8c 9c

Hand = 2h 3h

Hand = 2h 4h

Hand = 2h 6h 7h

Hand = 2h 6h 8h

Hand = 2h 6h 9h 10h

Hand = 2h 6h 9h jh

Hand = 2h 6h 9h qh kh

If anyone could point out to me where i am going wrong that would be helpful.">

[3297 byte] By [some1stolemyusernamea] at [2007-10-2 17:30:12]
# 1

>>Hello is there anyone there who can help me? I am writing a program that evaluates poker hands. I need a way of creating all 2 card combinations from the list of all cards not yet dealt.

--Well, I solved a similar poker problem, that 'normalize' any number of poker hands then 'rank' them in order from best to worst. If you need any help to normalize and rank poker hands then let me know. For an example:

Input:

4

8H 9D 8S 9C 8C

AS 2S 3S 4S 5S

TS JS 9H 8D QC

KC KS 2C 2H 2D

Output:

Normalize Hands:

4

8H 8S 8C 9D 9C

AS 5S 4S 3S 2S

QC JS TS 9H 8D

2C 2H 2D KC KS

Ranked Hands:

AS 5S 4S 3S 2S-> Straight-Flush

8H 8S 8C 9D 9C->Full-House

2C 2H 2D KC KS->Full-House

QC JS TS 9H 8D-->Straight

Good luck!

buteForcea at 2007-7-13 18:47:00 > top of Java-index,Other Topics,Algorithms...
# 2

Thankyou for you post.

I have written my code that ranks poker hands and that works fine.

However taking into account the 5 community cards and my 2 pocket cards I need a way of selecting all 2 card combinations from the remaining 45 cards left undealt.

Therefore I can add these combinations of 2 cards to the 5 community cards and then pass each new 7 card hand into a hand comparison class i have and tally how many times I win, how many times I lose and how many times I tie and then print this as a percentage. However I am struggling with a method that caclulates the combinations.

some1stolemyusernamea at 2007-7-13 18:47:01 > top of Java-index,Other Topics,Algorithms...
# 3

Following article has java code and explains subsets of a given size.

http://www.stefan-pochmann.de/spots/tutorials/sets_subsets/#Subsets_of_Specific_Size

The Combinatorial Object Server may also be interesting. You probably need the combinations with k=2:

http://www.theory.cs.uvic.ca/~cos/gen/comb.html

Ollebola at 2007-7-13 18:47:01 > top of Java-index,Other Topics,Algorithms...
# 4

To choose two different elements where order does not matter from a single array is simple

Card[] a;

for(int i = 0; i < a.length-1; i++){

for(int j = i+1; j < a.length; j++){

doSomethingWithTwoCards(a[i],a[j]);

}

}

If the things you want to choose from are scattered about in multiple arrays because you were doing something else where that other arrangement makes sense, well then collect them all together into a single array (or load references to them if you prefer into some new index array) and then use the simple code to choose all pairs of them.

Enjoy

marlin314a at 2007-7-13 18:47:01 > top of Java-index,Other Topics,Algorithms...
# 5
Thankyou for posting the reference to the web site. It was exactly tke kind of processing that I wanted and very well explained which will be most helpful.Thanks again
some1stolemyusernamea at 2007-7-13 18:47:01 > top of Java-index,Other Topics,Algorithms...