- Adding some foundation for Cogwork Librarian

- It seems like Booster Drafts weren't changing directions for the middle packs?
This commit is contained in:
Sol
2016-08-01 14:45:32 +00:00
parent 0669c4c0bd
commit b498fa5ee1
7 changed files with 85 additions and 62 deletions

View File

@@ -102,8 +102,15 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
// get next booster pack
this.boosterDraft.setChoice(card);
if (this.boosterDraft.hasNextChoice()) {
this.showChoices(this.boosterDraft.nextChoice());
boolean nextChoice = this.boosterDraft.hasNextChoice();
ItemPool<PaperCard> pool = null;
if (nextChoice) {
pool = this.boosterDraft.nextChoice();
nextChoice = pool != null && !pool.isEmpty();
}
if (nextChoice) {
this.showChoices(pool);
}
else {
this.saveDraft();
@@ -155,27 +162,6 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
// add sideboard to deck
deck.getOrCreate(DeckSection.Sideboard).addAll(this.getDeckManager().getPool());
//no need to add basic lands now that Add Basic Lands button exists
/*final String landSet = IBoosterDraft.LAND_SET_CODE[0].getCode();
final boolean isZendikarSet = landSet.equals("ZEN"); // we want to generate one kind of Zendikar lands at a time only
final boolean zendikarSetMode = MyRandom.getRandom().nextBoolean();
final int landsCount = 10;
for(String landName : MagicColor.Constant.BASIC_LANDS) {
int numArt = FModel.getMagicDb().getCommonCards().getArtCount(landName, landSet);
int minArtIndex = isZendikarSet ? (zendikarSetMode ? 1 : 5) : 1;
int maxArtIndex = isZendikarSet ? minArtIndex + 3 : numArt;
if (FModel.getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) {
for (int i = minArtIndex; i <= maxArtIndex; i++) {
deck.get(DeckSection.Sideboard).add(landName, landSet, i, numArt > 1 ? landsCount : 30);
}
} else {
deck.get(DeckSection.Sideboard).add(landName, landSet, 30);
}
}*/
return deck;
} // getPlayersDeck()

View File

@@ -110,11 +110,18 @@ public class CEditorQuestDraftingProcess extends ACEditorBase<PaperCard, DeckGro
// get next booster pack
boosterDraft.setChoice(card);
if (boosterDraft.hasNextChoice()) {
showChoices(boosterDraft.nextChoice());
boolean nextChoice = this.boosterDraft.hasNextChoice();
ItemPool<PaperCard> pool = null;
if (nextChoice) {
pool = this.boosterDraft.nextChoice();
nextChoice = !pool.isEmpty();
}
if (nextChoice) {
this.showChoices(pool);
}
else {
saveDraft();
this.saveDraft();
}
}

View File

@@ -74,6 +74,11 @@ public class BoosterDraftTest implements IBoosterDraft {
return this.n > 0;
}
@Override
public boolean isRoundOver() {
return hasNextChoice();
}
/**
* <p>
* getChosenCards.

View File

@@ -1361,6 +1361,8 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
BoosterDraft draft = parentScreen.getDraft();
draft.setChoice(card);
// TODO Implement handling of extra boosters
if (draft.hasNextChoice()) {
refresh();
}

View File

@@ -50,6 +50,8 @@ public class BoosterDraft implements IBoosterDraft {
protected int nextBoosterGroup = 0;
private int currentBoosterSize = 0;
private int currentBoosterPick = 0;
private int[] draftingBooster;
private List<List<PaperCard>> pack; // size 8
/** The draft picks. */
@@ -171,14 +173,6 @@ public class BoosterDraft implements IBoosterDraft {
protected BoosterDraft() {
this.draftFormat = LimitedPoolType.Full;
}
/**
* <p>
* Constructor for BoosterDraft_1.
* </p>
*
* @param draftType
* a {@link java.lang.String} object.
*/
protected BoosterDraft(final LimitedPoolType draftType) {
this.draftAI.setBd(this);
this.draftFormat = draftType;
@@ -237,13 +231,26 @@ public class BoosterDraft implements IBoosterDraft {
*/
@Override
public CardPool nextChoice() {
if (this.pack.get(this.getCurrentBoosterIndex()).isEmpty()) {
if (this.isRoundOver()) {
// If all packs are depleted crack 8 new packs
this.pack = this.get8BoosterPack();
if (this.pack == null) {
return null;
}
}
this.computerChoose();
final CardPool result = new CardPool();
result.addAllFlat(this.pack.get(this.getCurrentBoosterIndex()));
if (result.isEmpty()) {
// Can't set a card, since none are available. Just pass "empty" packs.
this.passPacks();
// Recur until we find a cardpool or finish
return nextChoice();
}
return result;
}
@@ -267,55 +274,64 @@ public class BoosterDraft implements IBoosterDraft {
this.nextBoosterGroup++;
this.currentBoosterSize = list.get(0).size();
this.currentBoosterPick = 0;
draftingBooster = new int[]{0, 1, 2, 3, 4, 5, 6, 7};
return list;
}
// size 7, all the computers decks
public void addSingleBoosterPack(int player, boolean random) {
// TODO Cogwork Librarian
}
/**
* <p>
* getDecks.
* </p>
*
* @return an array of {@link forge.deck.Deck} objects.
*/
// size 7, all the computers decks
@Override
public Deck[] getDecks() {
return this.draftAI.getDecks();
}
public void passPacks() {
// Alternate direction of pack passing
int adjust = this.nextBoosterGroup % 2 == 1 ? 1 : -1;
for(int i = 0; i < N_PLAYERS; i++) {
draftingBooster[i] = (draftingBooster[i] + adjust + pack.size()) % pack.size();
}
}
protected void computerChoose() {
final int iHumansBooster = this.getCurrentBoosterIndex();
int iPlayer = 0;
for (int i = 1; i < this.pack.size(); i++) {
final List<PaperCard> booster = this.pack.get((iHumansBooster + i) % this.pack.size());
final PaperCard aiPick = this.draftAI.choose(booster, iPlayer++);
booster.remove(aiPick);
// Loop through players 1-7 to draft their current pack
for (int i = 1; i < N_PLAYERS; i++) {
final List<PaperCard> booster = this.pack.get(this.draftingBooster[i]);
// Empty boosters can happen in a Conspiracy draft
if (!booster.isEmpty()) {
booster.remove(this.draftAI.choose(booster, i-1));
}
}
} // computerChoose()
/**
*
* Get the current booster index.
* Get the current booster index for the Human
* @return int
*/
public int getCurrentBoosterIndex() {
return this.currentBoosterPick % BoosterDraft.N_PLAYERS;
return this.draftingBooster[0];
}
/**
* <p>
* hasNextChoice.
* </p>
*
* @return a boolean.
*/
@Override
public boolean isRoundOver() {
for(List<PaperCard> singlePack : this.pack) {
if (!singlePack.isEmpty()) {
return false;
}
}
return true;
}
@Override
public boolean hasNextChoice() {
final boolean isLastGroup = this.nextBoosterGroup >= this.product.size();
final boolean isBoosterDepleted = this.currentBoosterPick >= this.currentBoosterSize;
final boolean noMoreCards = isLastGroup && isBoosterDepleted;
return !noMoreCards;
return this.nextBoosterGroup < this.product.size() || !this.isRoundOver();
}
/** {@inheritDoc} */
@@ -355,6 +371,7 @@ public class BoosterDraft implements IBoosterDraft {
thisBooster.remove(c);
this.currentBoosterPick++;
this.passPacks();
} // setChoice()
@Override

View File

@@ -58,6 +58,7 @@ public interface IBoosterDraft {
* @return a boolean.
*/
boolean hasNextChoice();
boolean isRoundOver();
/**
* <p>

View File

@@ -126,6 +126,11 @@ public class WinstonDraft extends BoosterDraft {
return getNextChoice(0) >= 0;
}
@Override
public boolean isRoundOver() {
return hasNextChoice();
}
public boolean isLastPileAndEmptyDeck(final int pile) {
return this.deck.size() == 0 && getNextChoice(pile+1) >= 0;
}