deck.addList(heap.drawRandom(1));
}
public CardList genDeck()
{
CardList heap = buildHeapList();
// generate deck from heap
CardList deck = new CardList();
if (heap.onlyWithTypes("Land").size() == 0) return deck;
double deckSize = csa.util.UtilityString.IntX(jTextFieldDecksize.getText(), 65);
double landPercent = csa.util.UtilityString.IntX(jTextFieldLand.getText(), 22);
maxSame = csa.util.UtilityString.IntX(jTextField4.getText(), 3);
double noLandsPercent = 100 - landPercent;
double cardPerPercent = deckSize/100;
int cardLands = (int) (landPercent*cardPerPercent);
int cardNoLands = (int) (noLandsPercent*cardPerPercent);
boolean toggle = true;
while (cardLands+cardNoLands <deckSize)
{
if (toggle)
cardLands++;
else
cardNoLands++;
toggle = !toggle;
}
int cardNowLands = 0;
while (cardNowLands<cardLands)
{
if (hasBlack) addLand(heap, deck, "B");cardNowLands = deck.size();if (cardNowLands>=cardLands) break;
if (hasWhite) addLand(heap, deck, "W");cardNowLands = deck.size();if (cardNowLands>=cardLands) break;
if (hasGreen) addLand(heap, deck, "G");cardNowLands = deck.size();if (cardNowLands>=cardLands) break;
if (hasRed) addLand(heap, deck, "R");cardNowLands = deck.size();if (cardNowLands>=cardLands) break;
if (hasBlue) addLand(heap, deck, "U");cardNowLands = deck.size();if (cardNowLands>=cardLands) break;
}
heap = heap.removeTypes("Land");
initBaseValues();
double allStrength = 0;
allStrength += healValue;
allStrength += creatureValue;
allStrength += playerDamageValue;
allStrength += creatureDamageValue;
allStrength += landDestroyValue;
allStrength += antiMagicValue;
allStrength += cardMagicValue;
allStrength += buffyValue;
allStrength += trickyValue;
if (allStrength == 0) return new CardList();
healPercent = healValue / allStrength;
creaturePercent = creatureValue / allStrength;
playerDamagePercent = playerDamageValue / allStrength;
creatureDamagePercent = creatureDamageValue / allStrength;
landDestroyPercent = landDestroyValue / allStrength;
antiMagicPercent = antiMagicValue / allStrength;
cardMagicPercent = cardMagicValue / allStrength;
buffyPercent = buffyValue / allStrength;
trickyPercent = trickyValue / allStrength;
double cardPercent = ((double)cardNoLands);///100.0;
healCards = (int) (cardPercent*healPercent);
creatureCards = (int) (cardPercent*creaturePercent);
playerDamageCards = (int) (cardPercent*playerDamagePercent);
creatureDamageCards = (int) (cardPercent*creatureDamagePercent);
landDestroyCards = (int) (cardPercent*landDestroyPercent);
antiMagicCards = (int) (cardPercent*antiMagicPercent);
cardMagicCards = (int) (cardPercent*cardMagicPercent);
buffyCards = (int) (cardPercent*buffyPercent);
trickyCards = (int) (cardPercent*trickyPercent);
int allCounted = healCards+creatureCards+playerDamageCards+creatureDamageCards+landDestroyCards+antiMagicCards+cardMagicCards+buffyCards+trickyCards;
while (allCounted<cardNoLands)
{
if(creaturePercent>0) {creatureCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(healPercent>0) {healCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(playerDamagePercent>0) {playerDamageCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(creatureDamagePercent>0) {creatureDamageCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(landDestroyPercent>0) {landDestroyCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(antiMagicPercent>0) {antiMagicCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cardMagicPercent>0) {cardMagicCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(buffyPercent>0) {buffyCards++;allCounted++;} if (allCounted>=cardNoLands) break;
if(trickyPercent>0) {trickyCards++;allCounted++;} if (allCounted>=cardNoLands) break;
}
double allCostStrength = 0;
allCostStrength += cost1Value;
allCostStrength += cost2Value;
allCostStrength += cost3Value;
allCostStrength += cost4Value;
allCostStrength += cost5Value;
allCostStrength += cost6Value;
allCostStrength += cost7Value;
allCostStrength += cost8Value;
allCostStrength += cost9Value;
allCostStrength += cost10Value;
if (allCostStrength == 0) return new CardList();
double cost1Percent = cost1Value / allCostStrength;
double cost2Percent = cost2Value / allCostStrength;
double cost3Percent = cost3Value / allCostStrength;
double cost4Percent = cost4Value / allCostStrength;
double cost5Percent = cost5Value / allCostStrength;
double cost6Percent = cost6Value / allCostStrength;
double cost7Percent = cost7Value / allCostStrength;
double cost8Percent = cost8Value / allCostStrength;
double cost9Percent = cost9Value / allCostStrength;
double cost10Percent = cost10Value / allCostStrength;
double costPercent = ((double)cardNoLands);///100.0;
int cost1 = (int) (costPercent*cost1Percent);
int cost2 = (int) (costPercent*cost2Percent);
int cost3 = (int) (costPercent*cost3Percent);
int cost4 = (int) (costPercent*cost4Percent);
int cost5 = (int) (costPercent*cost5Percent);
int cost6 = (int) (costPercent*cost6Percent);
int cost7 = (int) (costPercent*cost7Percent);
int cost8 = (int) (costPercent*cost8Percent);
int cost9 = (int) (costPercent*cost9Percent);
int cost10 = (int) (costPercent*cost10Percent);
allCounted = cost1+cost2+cost3+cost4+cost5+cost6+cost7+cost8+cost9+cost10;
while (allCounted<cardNoLands)
{
if(cost1Percent>0) {cost1++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost2Percent>0) {cost2++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost3Percent>0) {cost3++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost4Percent>0) {cost4++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost5Percent>0) {cost5++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost6Percent>0) {cost6++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost7Percent>0) {cost7++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost8Percent>0) {cost8++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost9Percent>0) {cost9++;allCounted++;} if (allCounted>=cardNoLands) break;
if(cost10Percent>0) {cost10++;allCounted++;} if (allCounted>=cardNoLands) break;
}
buildCurrents(cost1, allStrength);
while (cost1>0)
{
CardList subList = heap.getSubListByManaCost(1);
if (subList.size() == 0)
{
cost2+= cost1;
cost1=0;
break;
}
cost1 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost2, allStrength);
while (cost2>0)
{
CardList subList = heap.getSubListByManaCost(2);
if (subList.size() == 0)
{
cost3+= cost2;
cost2=0;
break;
}
cost2 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost3, allStrength);
while (cost3>0)
{
CardList subList = heap.getSubListByManaCost(3);
if (subList.size() == 0)
{
cost4+= cost3;
cost3=0;
break;
}
cost3 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost4, allStrength);
while (cost4>0)
{
CardList subList = heap.getSubListByManaCost(4);
if (subList.size() == 0)
{
cost5+= cost4;
cost4=0;
break;
}
cost4 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost5, allStrength);
while (cost5>0)
{
CardList subList = heap.getSubListByManaCost(5);
if (subList.size() == 0)
{
cost6+= cost5;
cost5=0;
break;
}
cost5 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost6, allStrength);
while (cost6>0)
{
CardList subList = heap.getSubListByManaCost(6);
if (subList.size() == 0)
{
cost7+= cost6;
cost6=0;
break;
}
cost6 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost7, allStrength);
while (cost7>0)
{
CardList subList = heap.getSubListByManaCost(7);
if (subList.size() == 0)
{
cost8+= cost7;
cost7=0;
break;
}
cost7 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost8, allStrength);
while (cost8>0)
{
CardList subList = heap.getSubListByManaCost(8);
if (subList.size() == 0)
{
cost9+= cost8;
cost8=0;
break;
}
cost8 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost9, allStrength);
while (cost9>0)
{
CardList subList = heap.getSubListByManaCost(9);
if (subList.size() == 0)
{
cost10+= cost9;
cost9=0;
break;
}
cost9 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
buildCurrents(cost10, allStrength);
while (cost10>0)
{
CardList subList = heap.getSubListByManaCostHigher(9);
if (subList.size() == 0)
{
cost10=0;
break;
}
cost10 -= addOneCard(deck, subList, heap);
if (getCurrentSum()==0) break;
}
// fill up with anything if we have not enough yet!
// addOneCard should handle the correct types
int i=0;
buildCurrents(((int)deckSize)-deck.size(), allStrength);
while (deck.size() != deckSize)
{
CardList subList = heap.copyList();
addOneCard(deck, subList, heap);
if (heap.size() == 0) break; // savety for not endless loop
i++;
if (i>100) break; // savety for not endless loop
}