public static int[] analyzeCards(int[] cards) {
int suitFlush = 0;
int[] unsuitedCards = new int[cards.length];
for (int i = 0; i < cards.length; i++) {
unsuitedCards[i] = (cards[i] % 13);
}
Arrays.sort(unsuitedCards);
unsuitedCards = reverse(unsuitedCards);
int[] lookForPairsHere=unsuitedCards.clone();
int[] suitsOfCards = new int[cards.length];
for (int i = 0; i < cards.length; i++) {
suitsOfCards[i] = cards[i] / 13;
}
int[] numberOfEachValuedCard = {0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0};
int[] pairs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
lookForPairsHere = unsuitedCards.clone();
int[] originalCards = cards.clone();
int[] condensedCards = {0, -1, 0, 0, 0, 0};
int[] suits = {0, 0, 0, 0};
boolean[] hasQuality = {false, false};
for (int i = 0; i < suitsOfCards.length; i++) {
suits[suitsOfCards[i]]++;
}
for (int i = 0; i < 4; i++) {
if (suits[i] > 4) {
hasQuality[0] = true;
suitFlush = i;
}
}
int[] straightCards = {-2, -2, -2, -2, -2, -2, -2};
int i = 0;
int j = 1;
int card = 0;
if(hasQuality[0]){
for (i = 0; i <originalCards.length; i++) {
if (originalCards[i]/13 == suitFlush) {
straightCards[i] = originalCards[i];
}
}
Arrays.sort(straightCards);
straightCards=reverse(straightCards);
unsuitedCards = removeDuplicates(unsuitedCards);
condensedCards[1]=straightCards[0]%13;
}
if (!hasQuality[0]) {
for(i=0;(i<unsuitedCards.length-5);i++){
if(unsuitedCards[i]-1==unsuitedCards[i+1]&&
unsuitedCards[i]-2==unsuitedCards[i+2]&&
unsuitedCards[i]-3==unsuitedCards[i+3]&&
unsuitedCards[i]-4==unsuitedCards[i+4]){
hasQuality[1]=true;
condensedCards[1]=unsuitedCards[i];
}
}
if (hasQuality[1] == false) {
int b = 0;
if (unsuitedCards[0] == 12) {
for (i = 0; i < unsuitedCards.length; i++) {
if (unsuitedCards[i] == 3 || unsuitedCards[i] == 2 || unsuitedCards[i] == 1
|| unsuitedCards[i] == 0) {
b++;
}
}
if (b>3) {
hasQuality[1] = true;
condensedCards[1] = 3;
}
}
}
} else {
Arrays.sort(straightCards);
straightCards = reverse(straightCards);
for(i=0;(i<straightCards.length-5);i++){
if(straightCards[i]-1==straightCards[i+1]&&
straightCards[i]-2==straightCards[i+2]&&
straightCards[i]-3==straightCards[i+3]&&
straightCards[i]-4==straightCards[i+4]){
hasQuality[1]=true;
condensedCards[1]=straightCards[i];
}
}
if (hasQuality[1] == false) {
int b = 0;
if (straightCards[0] == 12) {
for (int z = 0; (z< straightCards.length); z++){
if (straightCards[z] == 3 || straightCards[z] == 2 ||
straightCards[z] == 1
||straightCards[z] == 0) {
b++;
}
}
if (b>3) {
hasQuality[1] = true;
condensedCards[1] = 3;
}
}
}
}
if (hasQuality[1] && hasQuality[0]) {
condensedCards[0] = 8;
return condensedCards;
}
if (hasQuality[1] && !hasQuality[0]) {
condensedCards[0] = 4;
return condensedCards;
}
if (hasQuality[0] && !hasQuality[1]) {
condensedCards[0] = 5;
for(i=2;i<=5;i++){
condensedCards[i]=straightCards[i-1];
}
return condensedCards;
}
card = 0;
for (i = 0; i < lookForPairsHere.length; i++) {
numberOfEachValuedCard[lookForPairsHere[i]]++;
}
for (i = 12; i >= 0 && card < 5; i--) {
if (numberOfEachValuedCard[i] > 0) {
pairs[2 * card] = numberOfEachValuedCard[i];
pairs[2 * card + 1] = i;
card++;
}
}
int[] pairCondensed = {0, 0, 0, 0, 0};
for (i = 0; i < 5; i++) {
pairCondensed[i] = pairs[2 * i];
}
Arrays.sort(pairCondensed);
pairCondensed = reverse(pairCondensed);
if (pairCondensed[0] == 4 && pairCondensed[1] == 1) {
condensedCards[0] = 7;
for (i = 0; pairs[i] > 0; i += 2) {
if (pairs[i] == 4) {
condensedCards[1] = pairs[i + 1];
}
for (j = 0; j < 10; j += 2) {
if (pairs[j] == 1) {
condensedCards[2] = pairs[j + 1];
break;
}
}
}
return condensedCards;
}
if (pairCondensed[0] == 3 && pairCondensed[1] == 2) {
condensedCards[0] = 6;
for (i = 0; i < 10; i += 2) {
if (pairs[i] == 3) {
condensedCards[1] = pairs[i + 1];
}
if (pairs[i] == 2) {
condensedCards[2] = pairs[i + 1];
}
}
return condensedCards;
}
if (pairCondensed[0] == 3 && pairCondensed[1] == 1) {
condensedCards[0] = 3;
for (i = 0; i < 10; i += 2) {
if (pairs[i] == 3) {
condensedCards[1] = pairs[i + 1];
}
}
j = 3;
for (i = 0; j < 5; i++) {
if (unsuitedCards[i] != condensedCards[1]) {
condensedCards[j] = unsuitedCards[i];
j++;
}
}
}
if (pairCondensed[0] == 2 && pairCondensed[1] == 2) {
condensedCards[0] = 2;
for (i = 0; i < 10; i += 2) {
if (pairs[i] == 2 && condensedCards[1] == -1) {
condensedCards[1] = pairs[i + 1];
}
if (pairs[i] == 2 && condensedCards[1] != -1) {
condensedCards[2] = pairs[i + 1];
}
}
if (condensedCards[2] > condensedCards[1]) {
int temp2 = condensedCards[2];
int temp1 = condensedCards[1];
condensedCards[1] = temp2;
condensedCards[2] = temp1;
}
j = 3;
for (i = 0; j < 4; i++) {
if (unsuitedCards[i]
!= condensedCards[1] && unsuitedCards[i]
!= condensedCards[2]) {
condensedCards[j] = unsuitedCards[i];
j++;
}
}
}
if (pairCondensed[0] == 2&&pairCondensed[1]==1) {
condensedCards[0] = 1;
for (i = 0; i < 10; i += 2) {
if (pairs[i] == 2) {
condensedCards[1] = pairs[i + 1];
}
}
j = 3;
for (i = 0; j < 6 && i < 5; i++) {
if (unsuitedCards[i] != condensedCards[1]) {
condensedCards[j] = unsuitedCards[i];
j++;
}
}
}
if (condensedCards[0] == 0) {
for (i = 0,j=1; j <=5 && i < originalCards.length; i++) {
condensedCards[j]=lookForPairsHere[i];
j++;
}
}
return condensedCards;
}