// input should be ordered in ascending order based on recScore
int numScoreGroups = NUM_SCORE_GROUPS[numBoardCards];
if(recs.size() < numScoreGroups) {
// not a good situation
Collections.sort(recs, new ToupleIntComparator());
short[] paddedScores = new short[numScoreGroups];
for(int i = 0; i < recs.size(); i++) {
paddedScores[numScoreGroups - i - 1] = (short)Math.round(((ToupleFloatInt)recs.get(recs.size() - i - 1)).o1);
}
for(int i = 0; i < numScoreGroups-recs.size(); i++) {
paddedScores[i] = (short)Math.round(((ToupleFloatInt)recs.get(0)).o1);
}
return paddedScores;
}
while(recs.size() > numScoreGroups) {
// take the two closest scores, merge them
Collections.sort(recs, new ToupleFloatComparator());
float minDist = Float.MAX_VALUE;
// boolean tie = false;
int minDistIndex= -1;
float prevVal = ((ToupleFloatInt)recs.get(0)).o1;
for(int i = 0; i < (recs.size()-1); i++) {
float thisVal = ((ToupleFloatInt)recs.get(i+1)).o1;
float dist = thisVal-prevVal;
if(dist < minDist) {
minDist = dist;
minDistIndex = i;
}
prevVal = thisVal;
}
ToupleFloatInt greater = (ToupleFloatInt) recs.get(minDistIndex+1);
ToupleFloatInt lesser = (ToupleFloatInt) recs.get(minDistIndex);
double greaterWeight = ((double) greater.o2/
(greater.o2+lesser.o2));
greater.o1 = (float) (greaterWeight*greater.o1+(1-greaterWeight)*lesser.o1);
greater.o2 = greater.o2 + lesser.o2;
//now delete lesser from the list
recs.remove(minDistIndex);
}
Collections.sort(recs, new ToupleIntComparator());
short[] topScores = new short[numScoreGroups];
for(int i = 0; i < numScoreGroups; i++) {
topScores[i] = (short) Math.round(((ToupleFloatInt)recs.get(i)).o1);
}