I have a poker program and in that program I have method that checks if there is a four of kind in an array.
public boolean isFourOfAKind(Card[] arr){}
I change arr[] to an int array by grabbing each of the cards values, 2-14 and store them in a separate array. How do I check(efficiently) if 4 integers are the same in that array?
*NOTE: I am passing in an array of 7 cards
My Two Pair Method (From Requests)
/*
* Returns 0 if no two pairs
* else returns the highest card out of the two pairs,
* if two hands have the same highest pair then further inspection is needed
*/
public static int isTwoPair(Card[] arr){
int hold[] = new int[5];
int values[] = new int[arr.length];
int max = 0;
boolean total = false;
for(int i=0;i<arr.length;i++){
values[i] = arr[i].getValue();
}
for(int i = 0;i<values.length;i++){
for(int j = 0;j<values.length;j++){
if(i==j){
continue;
}
if(values[i]==values[j]){
if(values[i]>max){
max = values[i];
}
int hold1 =0;
int hold2=0;
hold1 = j;
hold2=i;
int counter = 0;
for(int ii = 0;ii<values.length;ii++){
if(ii==j||ii==i){
continue;
}
hold[counter] = values[ii];
counter++;
}
// for(int iii: hold){
// System.out.print(" , "+ iii);
// }
// System.out.println();
if(isPair(hold)==0){
max = 0;
total = false;
}else{
int holdInt = isPair(hold);
if(holdInt>max){
max = holdInt;
}
total = true;
}
}
}
}
return max;
}