Add some more SOI hints and clean up

This commit is contained in:
mcrawford620
2016-07-20 05:42:37 +00:00
parent 5c5af31bc3
commit 0d155118c6
23 changed files with 47 additions and 11 deletions

View File

@@ -14,12 +14,14 @@ import java.util.Map;
public class CardRanker {
private static final double SCORE_UNPICKABLE = -100.0;
// These factors determine the amount of boost given to a card's ranking for each other
// card that matches it's deckhints.
private static final Map<DeckHints.Type, Integer> typeFactors = ImmutableMap.<DeckHints.Type, Integer>builder()
.put(DeckHints.Type.ABILITY, 5)
.put(DeckHints.Type.ABILITY, 3)
.put(DeckHints.Type.COLOR, 1)
.put(DeckHints.Type.KEYWORD, 5)
.put(DeckHints.Type.NAME, 20)
.put(DeckHints.Type.TYPE, 5)
.put(DeckHints.Type.KEYWORD, 3)
.put(DeckHints.Type.NAME, 10)
.put(DeckHints.Type.TYPE, 3)
.build();
private static boolean logToConsole = false;
@@ -148,7 +150,7 @@ public class CardRanker {
Iterable<PaperCard> cards = cardsByType.get(type);
score += Iterables.size(cards) * typeFactors.get(type);
if (logToConsole && Iterables.size(cards) > 0) {
System.out.println(" -- Found " + Iterables.size(cards) + " cards for " + type);
System.out.println(" - " + card.getName() + ": Found " + Iterables.size(cards) + " cards for " + type);
}
}
}
@@ -159,7 +161,7 @@ public class CardRanker {
Iterable<PaperCard> cards = cardsByType.get(type);
score += Iterables.size(cards) * typeFactors.get(type);
if (logToConsole && Iterables.size(cards) > 0) {
System.out.println(" -- Found " + Iterables.size(cards) + " cards for " + type);
System.out.println(" - " + card.getName() + ": Found " + Iterables.size(cards) + " cards for " + type);
}
}
}

View File

@@ -66,7 +66,7 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
private Iterable<PaperCard> onColorCreatures;
private Iterable<PaperCard> onColorNonCreatures;
protected static final boolean logToConsole = true;
protected static final boolean logToConsole = false;
/**
*
@@ -337,8 +337,12 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
// total of all ClrCnts
int totalColor = 0;
int numColors = 0;
for (int i = 0; i < 5; i++) {
totalColor += clrCnts[i];
if (clrCnts[i] > 0) {
numColors++;
}
}
if (totalColor == 0) {
throw new RuntimeException("Add Lands to empty deck list!");
@@ -349,7 +353,13 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
for (int i = 0; i < 5; i++) {
if (clrCnts[i] > 0) {
// calculate number of lands for each color
final float p = (float) clrCnts[i] / (float) totalColor;
float p = (float) clrCnts[i] / (float) totalColor;
if (numColors == 2) {
// In the normal two-color case, constrain to within 40% and 60% so that the AI
// doesn't put too few lands of the lesser color, risking getting screwed on that color.
// Don't do this for the odd case where a third color had to be added to the deck.
p = Math.min(Math.max(p, 0.4f), 0.6f);
}
int nLand = Math.round(landsNeeded * p); // desired truncation to int
if (logToConsole) {
System.out.printf("Basics[%s]: %d/%d = %f%% = %d cards%n", MagicColor.Constant.BASIC_LANDS.get(i), clrCnts[i], totalColor, 100*p, nLand);
@@ -369,9 +379,9 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
}
}
// A common problem at this point is that nLand in the above loop was exactly 1/2,
// and it rounds up for both colors, and too many lands were added.
// If the deck size is > 40, remove the last land added.
// A common problem at this point is that p in the above loop was exactly 1/2,
// and nLand rounded up for both colors, so that one too many lands was added.
// So if the deck size is > 40, remove the last land added.
// Otherwise, the fixDeckSize() method would remove random cards.
while (deckList.size() > 40) {
deckList.remove(deckList.size() - 1);

View File

@@ -33,6 +33,9 @@ public class SealedDeckBuilder extends LimitedDeckBuilder {
private ColorSet chooseColors() {
// choose colors based on top 33% of cards
final List<PaperCard> colorChooserList = new ArrayList<PaperCard>();
// this is not exactly right, because the rankings here are taking into account deckhints
// for the whole set of cards, when some of those cards could be in colors that won't
// make it into the deck
List<PaperCard> initialRanked = ranker.rankCardsInDeck(getAiPlayables());
double limit = getAiPlayables().size() * .33;
for (int i = 0; i < limit; i++) {