// load up output file
// ------------------------------------------------------------
String outputPath = getOutputFileName(numBoardCards1, holeCards);
Helper.prepFilePath(outputPath);
WriteBinaryClusterIDTableStream out =
new WriteBinaryClusterIDTableStream(
outputPath, numBoardCards1, numBoardCards2, holeCards,
in1.getNumClusters(), in2.getNumClusters(),
Helper.getBufferSize(MAX_SIMULT_FILES_OPEN));
// ------------------------------------------------------------
// read input for numBoardCards2 into array for random access
// ------------------------------------------------------------
byte[][][][][] newClusterIds = new byte[Card.NUM_CARDS+1]
[Card.NUM_CARDS+1]
[Card.NUM_CARDS+1]
[Card.NUM_CARDS+1]
[Card.NUM_CARDS+1];
HandRecordClusterId hr2;
double arrayPopulateTimer = System.currentTimeMillis();
int numEntriesToPopulate = Constants.choose(Card.NUM_CARDS-2, numBoardCards2);
int modVal = (int)Math.floor(numEntriesToPopulate/100);
if(isFiveBcs) {
int counter = 0;
int percent = 0;
while((hr2 = in2.readRecord()) != null) {
byte[] boardCards2Copy = hr2.boardCards;
newClusterIds[boardCards2Copy[0]]
[boardCards2Copy[1]]
[boardCards2Copy[2]]
[boardCards2Copy[3]]
[boardCards2Copy[4]] = hr2.clusterId;
if(++counter % modVal == 0) {
// System.out.println(" " + (percent++) + "% done populating array");
}
}
} else {
while((hr2 = in2.readRecord()) != null) {
byte[] boardCards2Copy = new byte[5];
for(int i = 0; i < numBoardCards2; i++) {
boardCards2Copy[i] = hr2.boardCards[i];
}
for(int i = numBoardCards2; i < 5; i++) {
boardCards2Copy[i] = Card.NUM_CARDS;
}
newClusterIds[boardCards2Copy[0]]
[boardCards2Copy[1]]
[boardCards2Copy[2]]
[boardCards2Copy[3]]
[boardCards2Copy[4]] = hr2.clusterId;
}
}
// System.out.println(" load array: " +
// (System.currentTimeMillis() - arrayPopulateTimer));
// ------------------------------------------------------------
// create output
// ------------------------------------------------------------
// for each (50 choose numBoardCards1) ...
// print clusterId for numBoardCards1
// loop through all possible (50 choose numBoardCards2) boardcards,
// merge each one with our holecards to get the candidates for the
// next card-turn. For each of those, look up the cluster ID for
// these holecards and print that out
HandRecordClusterId hr1;
// each output sequence (for each boardCard config) will now:
// 1) be the same length
// 2) be in the same order, given the boardcards
// output cluster ID will only be Byte.MAX_VALUE if the newly delt
// card is one of the ones in these holecards.
while((hr1 = in1.readRecord()) != null) {
// first print the master clusterId for numBoardCards1
out.putClusterId(hr1.clusterId);
Combinations nextHandAddCards = new Combinations(
Helper.getRemainingCards(hr1.boardCards),
(numBoardCards2 - numBoardCards1)); //hot spot?
byte[] addCards;
while(nextHandAddCards.hasMoreElements()) {
addCards = nextHandAddCards.nextElement();
boolean legalGivenHCs = true;
for(int i = 0; i < addCards.length; i++) {
if(addCards[i] == holeCards[0] ||
addCards[i] == holeCards[1]) {
legalGivenHCs = false;
break;
}
}
if(legalGivenHCs) {
byte[] newHand = Helper.mergeOrderedByteArrays(
hr1.boardCards, addCards);
byte newClusterId = -1;
if(isFiveBcs) {
newClusterId = newClusterIds[newHand[0]]
[newHand[1]]
[newHand[2]]
[newHand[3]]
[newHand[4]];
} else {
byte[] newBcs = new byte[5];
for(int i = 0; i < numBoardCards2; i++) {
newBcs[i] = newHand[i];
}
for(int i = numBoardCards2; i < 5; i++) {
newBcs[i] = Card.NUM_CARDS;
}
newClusterId = newClusterIds[newBcs[0]]
[newBcs[1]]
[newBcs[2]]
[newBcs[3]]
[newBcs[4]];
}
out.putClusterId(newClusterId);
} else {
out.putClusterId(Byte.MAX_VALUE); // place holder!
}
}
}
out.close();
deleteLock(numBoardCards1, holeCards);
System.out.println(" Iteration " + ((int) Math.floor(100*((double) ++iterationCounter/numIterations))) + "% done in time: " + (System.currentTimeMillis() - tIteration));
}
System.out.println("numBoardCards " + numBoardCards1 + "->" + numBoardCards2 + " completed in time: " + (System.currentTimeMillis() - tBoardCards));